configurer 0.4.0 → 0.4.1
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/VERSION +1 -1
- data/lib/configurer.rb +13 -10
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/configurer.rb
CHANGED
@@ -2,29 +2,32 @@
|
|
2
2
|
|
3
3
|
module Configurer
|
4
4
|
def eigenclass; (class<<self;self;end); end
|
5
|
+
CONFIGS = {}
|
5
6
|
|
6
|
-
class Config <
|
7
|
-
|
8
|
-
def
|
7
|
+
class Config < Module
|
8
|
+
attr_accessor :arr
|
9
|
+
def method_missing(sym, &blk); arr.first[sym] = blk; end
|
9
10
|
def []=(sym, blk)
|
10
|
-
|
11
|
-
|
12
|
-
mod.send(:define_method, sym) do
|
11
|
+
(arr = self.arr).last[sym] = blk
|
12
|
+
define_method sym do
|
13
13
|
frame = Module===self ? self : self.class
|
14
|
-
|
14
|
+
blk = arr.inject(nil){ |m, e| m || e[sym] }
|
15
|
+
frame.instance_exec(&blk)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
::WORLDWIDE = Config.new
|
20
|
-
|
20
|
+
::WORLDWIDE = Config.new
|
21
|
+
::WORLDWIDE.arr = [{}]
|
21
22
|
|
22
23
|
def config sym = nil, &blk
|
23
24
|
!sym and CONFIGS[self] or CONFIGS[self][sym] = blk
|
24
25
|
end
|
25
26
|
|
26
27
|
def config_from klass
|
27
|
-
|
28
|
+
CONFIGS[klass] ||= Config.new
|
29
|
+
CONFIGS[klass].arr ||= [{}]+::WORLDWIDE.arr+[{}]
|
30
|
+
[self, eigenclass].each{ |x| x.send :include, CONFIGS[klass] }
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.extend_object klass
|