Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support array of hashes

  • Loading branch information...
commit 23db3f773ff167fb8b83e2e942d0df046d32e73e 1 parent 6be535a
@andreychernih andreychernih authored
View
8 lib/settingslogic.rb
@@ -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
8 spec/settings.yml
@@ -19,4 +19,10 @@ collides:
does: not
nested:
collides:
- does: not either
+ does: not either
+
+array:
+ -
+ name: first
+ -
+ name: second
View
4 spec/settingslogic_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.