configurer 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/configurer.rb +9 -8
- data/test/test_configurer.rb +1 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/configurer.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# a new take on ruby cross-class configuration
|
2
2
|
|
3
3
|
module Configurer
|
4
|
-
class
|
5
|
-
def method_missing(meth, *args, &blk);
|
4
|
+
class Hashwrapper < Struct.new(:hash)
|
5
|
+
def method_missing(meth, *args, &blk); hash[meth] = blk; end
|
6
6
|
end
|
7
7
|
|
8
|
-
::WORLDWIDE =
|
8
|
+
::WORLDWIDE = Hashwrapper.new({})
|
9
9
|
|
10
10
|
def config *syms, &blk
|
11
|
-
return @
|
12
|
-
|
11
|
+
return Hashwrapper.new(@class_overides) if syms.empty?
|
12
|
+
@class_defaults ||= {}
|
13
|
+
configs = @class_overides ||= Hash.new{|h,k| ::WORLDWIDE.hash[k] || @class_defaults[k]}
|
13
14
|
syms.each do |sym|
|
14
|
-
|
15
|
-
define_method(sym){ self.class.instance_exec &
|
16
|
-
(class << self;self;end).send(:define_method, sym){ instance_exec &
|
15
|
+
@class_defaults[sym] = blk if blk
|
16
|
+
define_method(sym){ self.class.instance_exec &configs[sym] }
|
17
|
+
(class << self;self;end).send(:define_method, sym){ instance_exec &configs[sym] }
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/test/test_configurer.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joe Edelman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-09 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|