Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

slight reorg and added spec demonstrating remaining edge case

  • Loading branch information...
commit 872a103261b827d5d363ea6ba35f70cca4f191c3 1 parent 77825ec
Nate Wiger authored committed
Showing with 20 additions and 2 deletions.
  1. +7 −2 lib/settingslogic.rb
  2. +13 −0 spec/settingslogic_spec.rb
9 lib/settingslogic.rb
View
@@ -73,10 +73,15 @@ def method_missing(name, *args, &block)
# 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:
13 spec/settingslogic_spec.rb
View
@@ -91,8 +91,21 @@
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'
Please sign in to comment.
Something went wrong with that request. Please try again.