Commit 872a103261b827d5d363ea6ba35f70cca4f191c3
Committed by
Ben Johnson
1 parent
77825ec0
Exists in
master
slight reorg and added spec demonstrating remaining edge case
Showing
2 changed files
with
20 additions
and
2 deletions
Show diff stats
lib/settingslogic.rb
@@ -73,10 +73,15 @@ class Settingslogic < Hash | @@ -73,10 +73,15 @@ class Settingslogic < Hash | ||
73 | # of the singleton pattern. Basically this proxies Setting.foo to Setting.instance.foo | 73 | # of the singleton pattern. Basically this proxies Setting.foo to Setting.instance.foo |
74 | def create_accessors! | 74 | def create_accessors! |
75 | instance.each do |key,val| | 75 | instance.each do |key,val| |
76 | - next unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval | ||
77 | - instance_eval "def #{key}; instance.send(:#{key}); end" | 76 | + create_accessor_for(key) |
78 | end | 77 | end |
79 | end | 78 | end |
79 | + | ||
80 | + def create_accessor_for(key) | ||
81 | + return unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval | ||
82 | + instance_eval "def #{key}; instance.send(:#{key}); end" | ||
83 | + end | ||
84 | + | ||
80 | end | 85 | end |
81 | 86 | ||
82 | # Initializes a new settings object. You can initialize an object in any of the following ways: | 87 | # Initializes a new settings object. You can initialize an object in any of the following ways: |
spec/settingslogic_spec.rb
@@ -91,8 +91,21 @@ describe "Settingslogic" do | @@ -91,8 +91,21 @@ describe "Settingslogic" do | ||
91 | Settings.language[:erlang] = {} | 91 | Settings.language[:erlang] = {} |
92 | Settings.language[:erlang][:paradigm] = 'functional' | 92 | Settings.language[:erlang][:paradigm] = 'functional' |
93 | Settings.language.erlang.paradigm.should == 'functional' | 93 | Settings.language.erlang.paradigm.should == 'functional' |
94 | + | ||
95 | + Settings[:toplevel] = '42' | ||
96 | + Settings.toplevel.should == '42' | ||
94 | end | 97 | end |
95 | 98 | ||
99 | + # This one edge case currently does not pass, because it requires very | ||
100 | + # esoteric code in order to make it pass. It was judged not worth fixing, | ||
101 | + # as it introduces significant complexity for minor gain. | ||
102 | + # it "should handle reloading top-level settings" | ||
103 | + # Settings[:inspect] = 'yeah baby' | ||
104 | + # Settings.inspect.should == 'yeah baby' | ||
105 | + # Settings.reload! | ||
106 | + # Settings.inspect.should == 'Settings' | ||
107 | + # end | ||
108 | + | ||
96 | it "should handle oddly-named settings" do | 109 | it "should handle oddly-named settings" do |
97 | Settings.language['some-dash-setting#'] = 'dashtastic' | 110 | Settings.language['some-dash-setting#'] = 'dashtastic' |
98 | Settings.language['some-dash-setting#'].should == 'dashtastic' | 111 | Settings.language['some-dash-setting#'].should == 'dashtastic' |