binarylogic-settingslogic 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION.yml +1 -1
- data/lib/settingslogic.rb +6 -26
- data/settingslogic.gemspec +1 -1
- data/spec/settingslogic_spec.rb +0 -4
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 2.0.2 released 2009-08-22
|
2
|
+
|
3
|
+
* Define methods during method_missing instead of during initialization. Allows for modification on the fly.
|
4
|
+
|
1
5
|
== 2.0.0 released 2009-08-22
|
2
6
|
|
3
7
|
* Less magic, instead of automatically defining a Settings constant, you should define your own constant. See the readme for an example.
|
data/VERSION.yml
CHANGED
data/lib/settingslogic.rb
CHANGED
@@ -3,8 +3,6 @@ require "erb"
|
|
3
3
|
|
4
4
|
# A simple settings solution using a YAML file. See README for more information.
|
5
5
|
class Settingslogic < Hash
|
6
|
-
class UndefinedSetting < StandardError; end
|
7
|
-
|
8
6
|
class << self
|
9
7
|
def name # :nodoc:
|
10
8
|
instance.key?("name") ? instance.name : super
|
@@ -54,34 +52,16 @@ class Settingslogic < Hash
|
|
54
52
|
hash = hash[self.class.namespace] if self.class.namespace
|
55
53
|
self.update hash
|
56
54
|
end
|
57
|
-
|
58
|
-
define_settings!
|
59
55
|
end
|
60
56
|
|
61
57
|
private
|
62
58
|
def method_missing(name, *args, &block)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
when Hash
|
70
|
-
instance_eval <<-"end_eval", __FILE__, __LINE__
|
71
|
-
def #{key}
|
72
|
-
@#{key} ||= self.class.new(self[#{key.inspect}])
|
73
|
-
end
|
74
|
-
end_eval
|
75
|
-
else
|
76
|
-
instance_eval <<-"end_eval", __FILE__, __LINE__
|
77
|
-
def #{key}
|
78
|
-
@#{key} ||= self[#{key.inspect}]
|
79
|
-
end
|
80
|
-
def #{key}=(value)
|
81
|
-
@#{key} = value
|
82
|
-
end
|
83
|
-
end_eval
|
84
|
-
end
|
59
|
+
if key?(name.to_s)
|
60
|
+
value = self[name.to_s].is_a?(Hash) ? self.class.new(self[name.to_s]) : self[name.to_s]
|
61
|
+
self.class.send(:define_method, name) { value }
|
62
|
+
send(name)
|
63
|
+
else
|
64
|
+
super
|
85
65
|
end
|
86
66
|
end
|
87
67
|
end
|
data/settingslogic.gemspec
CHANGED
data/spec/settingslogic_spec.rb
CHANGED
@@ -17,10 +17,6 @@ describe "Settingslogic" do
|
|
17
17
|
Settings.setting3.should == 25
|
18
18
|
end
|
19
19
|
|
20
|
-
it "should raise an error for unfound settings" do
|
21
|
-
lambda { Settings.undefined }.should raise_error(Settingslogic::UndefinedSetting)
|
22
|
-
end
|
23
|
-
|
24
20
|
it "should namespace settings" do
|
25
21
|
Settings2.setting1_child.should == "saweet"
|
26
22
|
end
|