configurer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/configurer.rb CHANGED
@@ -9,11 +9,11 @@ module Configurer
9
9
 
10
10
  def config *syms, &blk
11
11
  return @configurer if syms.empty?
12
- configurer = @configurer ||= HashMM.new{|h,k| WORLDWIDE[k] || blk }
12
+ configurer = @configurer ||= HashMM.new{|h,k| ::WORLDWIDE[k] || blk }
13
13
  syms.each do |sym|
14
14
  meth = proc{ configurer[sym].call }
15
- define_method(sym, &meth)
16
- (class << self;self;end).send(:define_method, sym, &meth)
15
+ define_method(sym){ self.class.instance_exec &configurer[sym] }
16
+ (class << self;self;end).send(:define_method, sym){ instance_exec &configurer[sym] }
17
17
  end
18
18
  end
19
19
  end
@@ -24,4 +24,29 @@ class TestConfigable < Test::Unit::TestCase
24
24
  Foo.new.try
25
25
  raise unless THING.first == :bye
26
26
  end
27
+
28
+ should "work without a global config" do
29
+ class Foo2
30
+ extend Configurer; config :baz do :bad end
31
+ end
32
+
33
+ x = Foo2.new
34
+ assert_equal :bad, Foo2.baz
35
+ assert_equal :bad, x.baz
36
+
37
+ Foo2.config.baz { :good }
38
+ assert_equal :good, Foo2.baz
39
+ assert_equal :good, x.baz
40
+ end
41
+
42
+ should "run in the subclass context" do
43
+ class ::A; extend Configurer; config :f do name end; end
44
+ class ::B < ::A; end
45
+
46
+ assert_equal 'A', A.f
47
+ assert_equal 'A', A.new.f
48
+ assert_equal 'B', B.f
49
+ assert_equal 'B', B.new.f
50
+ end
51
+
27
52
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Edelman