settingslogic 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 2
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
- raise UndefinedSetting.new("The '#{name}' was not found in your configuration file: #{self.class.source}")
64
- end
65
-
66
- def define_settings!
67
- self.each do |key, value|
68
- case value
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{settingslogic}
8
- s.version = "2.0.1"
8
+ s.version = "2.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingslogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic