Permalink
Browse files

Support array of hashes

  • Loading branch information...
andreychernih committed Oct 30, 2012
1 parent 6be535a commit 23db3f773ff167fb8b83e2e942d0df046d32e73e
Showing with 18 additions and 2 deletions.
  1. +7 −1 lib/settingslogic.rb
  2. +7 −1 spec/settings.yml
  3. +4 −0 spec/settingslogic_spec.rb
View
@@ -164,7 +164,13 @@ def #{key}
return @#{key} if @#{key}
return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? '#{key}'
value = fetch('#{key}')
- @#{key} = value.is_a?(Hash) ? self.class.new(value, "'#{key}' section in #{@section}") : value
+ @#{key} = if value.is_a?(Hash)
+ self.class.new(value, "'#{key}' section in #{@section}")
+ elsif value.is_a?(Array) && value.all?{|v| v.is_a? Hash}
+ value.map{|v| self.class.new(v)}
+ else
+ value
+ end
end
EndEval
end
View
@@ -19,4 +19,10 @@ collides:
does: not
nested:
collides:
- does: not either
+ does: not either
+
+array:
+ -
+ name: first
+ -
+ name: second
@@ -9,6 +9,10 @@
Settings.setting1.setting1_child.should == "saweet"
end
+ it "should access settings in nested arrays" do
+ Settings.array.first.name.should == "first"
+ end
+
it "should access deep nested settings" do
Settings.setting1.deep.another.should == "my value"
end

0 comments on commit 23db3f7

Please sign in to comment.