diff --git a/lib/settingslogic.rb b/lib/settingslogic.rb index 5996e59..e5c12fd 100644 --- a/lib/settingslogic.rb +++ b/lib/settingslogic.rb @@ -73,10 +73,15 @@ class Settingslogic < Hash # of the singleton pattern. Basically this proxies Setting.foo to Setting.instance.foo def create_accessors! instance.each do |key,val| - next unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval - instance_eval "def #{key}; instance.send(:#{key}); end" + create_accessor_for(key) end end + + def create_accessor_for(key) + return unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval + instance_eval "def #{key}; instance.send(:#{key}); end" + end + end # Initializes a new settings object. You can initialize an object in any of the following ways: diff --git a/spec/settingslogic_spec.rb b/spec/settingslogic_spec.rb index 4034a46..24ed978 100644 --- a/spec/settingslogic_spec.rb +++ b/spec/settingslogic_spec.rb @@ -91,8 +91,21 @@ describe "Settingslogic" do Settings.language[:erlang] = {} Settings.language[:erlang][:paradigm] = 'functional' Settings.language.erlang.paradigm.should == 'functional' + + Settings[:toplevel] = '42' + Settings.toplevel.should == '42' end + # This one edge case currently does not pass, because it requires very + # esoteric code in order to make it pass. It was judged not worth fixing, + # as it introduces significant complexity for minor gain. + # it "should handle reloading top-level settings" + # Settings[:inspect] = 'yeah baby' + # Settings.inspect.should == 'yeah baby' + # Settings.reload! + # Settings.inspect.should == 'Settings' + # end + it "should handle oddly-named settings" do Settings.language['some-dash-setting#'] = 'dashtastic' Settings.language['some-dash-setting#'].should == 'dashtastic' -- libgit2 0.21.0