Merge pull request #880 from willkoehler/add_hash_features_to_datastore
Add [] operator and has_key? to DataStore to make DataStore act like a hash
This commit is contained in:
commit
02d476f440
1 changed files with 14 additions and 1 deletions
|
@ -179,7 +179,20 @@ module Middleman
|
|||
|
||||
# Needed so that method_missing makes sense
|
||||
def respond_to?(method, include_private = false)
|
||||
super || @local_data.has_key?(method.to_s) || !!(data_for_path(method))
|
||||
super || has_key?(method)
|
||||
end
|
||||
|
||||
# Make DataStore act like a hash. Return requested data, or
|
||||
# nil if data does not exist
|
||||
#
|
||||
# @param [String, Symbol] key The name of the data namespace
|
||||
# @return [Hash, nil]
|
||||
def [](key)
|
||||
__send__(key) if has_key?(key)
|
||||
end
|
||||
|
||||
def has_key?(key)
|
||||
@local_data.has_key?(key.to_s) || !!(data_for_path(key))
|
||||
end
|
||||
|
||||
# Convert all the data into a static hash
|
||||
|
|
Loading…
Reference in a new issue