simply_configurable 0.0.2 → 0.1.0
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 -1
- data/README.rdoc +21 -0
- data/lib/simply_configurable/version.rb +1 -1
- data/lib/simply_configurable.rb +11 -1
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
= Simply Configurable
|
2
2
|
|
3
|
+
== Version 0.1.0
|
4
|
+
* Added capability to nest SimplyConfigurable classes (see README)
|
5
|
+
|
3
6
|
== Version 0.0.2
|
4
|
-
*
|
7
|
+
* Allows nested hash values (before, "MyClass.config :foo => {}" threw an error)
|
5
8
|
|
6
9
|
== Version 0.0.1
|
7
10
|
* Initial release
|
data/README.rdoc
CHANGED
@@ -43,3 +43,24 @@ The #config method is defined on both the class and its instances, so it may be
|
|
43
43
|
|
44
44
|
This library uses the HashWithIndifferentAccess class of the ActiveSupport library, allowing you to access/set config values by either symbol or string.
|
45
45
|
|
46
|
+
== Nesting
|
47
|
+
|
48
|
+
Any subclasses of a SimplyConfigurable class will also be SimplyConfigurable. The subclass will inherit all config values from its ancestors, but any values set on the subclass will not overwrite those on the ancestors.
|
49
|
+
|
50
|
+
For example:
|
51
|
+
|
52
|
+
class Foo
|
53
|
+
include SimplyConfigurable
|
54
|
+
|
55
|
+
config :color => 'red'
|
56
|
+
config :style => 'awesome'
|
57
|
+
end
|
58
|
+
|
59
|
+
class Bar < Foo
|
60
|
+
config :style => 'less awesome'
|
61
|
+
end
|
62
|
+
|
63
|
+
Foo.config[:style] # returns 'awesome'
|
64
|
+
Bar.config[:style] # returns 'less awesome'
|
65
|
+
Bar.config[:color] # returns 'red'
|
66
|
+
|
data/lib/simply_configurable.rb
CHANGED
@@ -21,7 +21,17 @@ module SimplyConfigurable
|
|
21
21
|
@config.merge!(options || {})
|
22
22
|
end
|
23
23
|
|
24
|
-
@config
|
24
|
+
superclass_config.merge(@config)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def superclass_config
|
30
|
+
if self.superclass.include?(SimplyConfigurable)
|
31
|
+
self.superclass.config
|
32
|
+
else
|
33
|
+
{}.with_indifferent_access
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
end
|