configurer 0.1.1 → 0.3.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
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 HashMM < Hash
5
- def method_missing(meth, *args, &blk); self[meth] = blk; end
4
+ class Hashwrapper < Struct.new(:hash)
5
+ def method_missing(meth, *args, &blk); hash[meth] = blk; end
6
6
  end
7
7
 
8
- ::WORLDWIDE = HashMM.new
8
+ ::WORLDWIDE = Hashwrapper.new({})
9
9
 
10
10
  def config *syms, &blk
11
- return @configurer if syms.empty?
12
- configurer = @configurer ||= HashMM.new{|h,k| ::WORLDWIDE[k] || blk }
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
- meth = proc{ configurer[sym].call }
15
- define_method(sym){ self.class.instance_exec &configurer[sym] }
16
- (class << self;self;end).send(:define_method, sym){ instance_exec &configurer[sym] }
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
@@ -13,7 +13,7 @@ class TestConfigable < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  WORLDWIDE.bar { THING.push :hi; :good }
16
- assert WORLDWIDE[:bar]
16
+ assert WORLDWIDE.hash[:bar]
17
17
 
18
18
  Foo.new.try
19
19
  assert_equal :hi, THING.first
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
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-08 00:00:00 -04:00
17
+ date: 2010-09-09 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20