feat(data): allow for setting & getting Arrays through #store & #data_for_path

Seeing that in #touch_file that a value in data could be an Array or Hash, loosen contracts to allow for other storage & retrieval methods to set the same types. Array & Hash being allowable is strongly tied to what *could* be returned after passing through Util.recursively_enhance

[close #1803]
This commit is contained in:
Steven Sloan 2016-02-17 16:58:04 -05:00
parent a24e5986a2
commit fc0f5d24d6
3 changed files with 110 additions and 4 deletions

View file

@ -67,7 +67,7 @@ module Middleman
# @param [Symbol] name Name of the data, used for namespacing
# @param [Hash] content The content for this data
# @return [Hash]
Contract Symbol, Hash => Hash
Contract Symbol, Or[Hash, Array] => Hash
def store(name=nil, content=nil)
@local_sources[name.to_s] = content unless name.nil? || content.nil?
@local_sources
@ -148,7 +148,7 @@ module Middleman
#
# @param [String, Symbol] path The name of the data namespace
# @return [Hash, nil]
Contract Or[String, Symbol] => Maybe[Hash]
Contract Or[String, Symbol] => Maybe[Or[Array, IsA['Middleman::Util::EnhancedHash']]]
def data_for_path(path)
response = if store.key?(path.to_s)
store[path.to_s]