Commit ea15363811fad493c90596007b592ed0d7322ae2

Authored by Ben Johnson
2 parents 184afc7b 3420a831
Exists in master

Merge pull request #41 from ebeigarts/fix-falsy-settings

Fix dynamic settings with falsy values
lib/settingslogic.rb
... ... @@ -163,7 +163,7 @@ class Settingslogic < Hash
163 163 # http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/
164 164 def create_accessor_for(key, val=nil)
165 165 return unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval
166   - instance_variable_set("@#{key}", val) if val
  166 + instance_variable_set("@#{key}", val)
167 167 self.class.class_eval <<-EndEval
168 168 def #{key}
169 169 return @#{key} if @#{key}
... ...
spec/settingslogic_spec.rb
... ... @@ -130,6 +130,18 @@ describe &quot;Settingslogic&quot; do
130 130 Settings.language['some-dash-setting#'].should == 'dashtastic'
131 131 end
132 132  
  133 + it "should handle settings with nil value" do
  134 + Settings["flag"] = true
  135 + Settings["flag"] = nil
  136 + Settings.flag.should == nil
  137 + end
  138 +
  139 + it "should handle settings with false value" do
  140 + Settings["flag"] = true
  141 + Settings["flag"] = false
  142 + Settings.flag.should == false
  143 + end
  144 +
133 145 it "should support instance usage as well" do
134 146 settings = SettingsInst.new(Settings.source)
135 147 settings.setting1.setting1_child.should == "saweet"
... ...