Skip to content

Commit ea15363

Browse files
committedDec 30, 2012
Merge pull request binarylogic#41 from ebeigarts/fix-falsy-settings
Fix dynamic settings with falsy values
2 parents 184afc7 + 3420a83 commit ea15363

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎lib/settingslogic.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def create_accessors!
163163
# http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/
164164
def create_accessor_for(key, val=nil)
165165
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)
167167
self.class.class_eval <<-EndEval
168168
def #{key}
169169
return @#{key} if @#{key}

‎spec/settingslogic_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ class NoSource < Settingslogic; end
130130
Settings.language['some-dash-setting#'].should == 'dashtastic'
131131
end
132132

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+
133145
it "should support instance usage as well" do
134146
settings = SettingsInst.new(Settings.source)
135147
settings.setting1.setting1_child.should == "saweet"

0 commit comments

Comments
 (0)
Please sign in to comment.