dyoder-autocode 0.9.6 → 0.9.7
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/lib/autocode.rb +11 -15
- data/test/autoinit.rb +1 -1
- data/test/helpers.rb +2 -1
- data/test/test_lib/answer42_it_is.rb +9 -0
- data/test/test_lib/humbug.rb +9 -0
- data/test/test_lib/the_class42_gang.rb +9 -0
- data/test/test_lib/the_one_and_only_class.rb +9 -0
- data/test/test_lib/the_one_and_only_module.rb +9 -0
- data/test/test_lib/the_pretender.rb +9 -0
- metadata +8 -2
data/lib/autocode.rb
CHANGED
@@ -25,29 +25,25 @@ module Autocode
|
|
25
25
|
return self
|
26
26
|
end
|
27
27
|
|
28
|
-
def autocreate_class( key = true, superclass = Class )
|
29
|
-
autocreate key, Class.new( superclass )
|
28
|
+
def autocreate_class( key = true, superclass = Class, &block )
|
29
|
+
autocreate( key, Class.new( superclass ), &block )
|
30
30
|
end
|
31
31
|
|
32
|
-
def autocreate_module( key = true )
|
33
|
-
autocreate key, Module.new
|
32
|
+
def autocreate_module( key = true, &block )
|
33
|
+
autocreate( key, Module.new, &block )
|
34
34
|
end
|
35
35
|
|
36
36
|
def autoinit( key, &block )
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if match
|
42
|
-
namespace, cname = match[1,2]
|
43
|
-
const = module_eval(namespace)
|
44
|
-
const.module_eval do
|
45
|
-
@init_blocks ||= Hash.new { |h,k| h[k] = [] }
|
46
|
-
@init_blocks[cname.to_sym] << block
|
37
|
+
if match = key.to_s.match(/^([\w\d_]+)::(.*)$/)
|
38
|
+
const, rest = match[1,2]
|
39
|
+
autoinit(const.to_sym) do
|
40
|
+
autoinit(rest, &block)
|
47
41
|
end
|
48
42
|
else
|
49
|
-
@init_blocks[
|
43
|
+
@init_blocks ||= Hash.new { |h,k| h[k] = [] }
|
44
|
+
@init_blocks[key.to_sym] << block
|
50
45
|
end
|
46
|
+
|
51
47
|
return self
|
52
48
|
end
|
53
49
|
|
data/test/autoinit.rb
CHANGED
@@ -44,7 +44,7 @@ describe "thingy" do
|
|
44
44
|
Thingy.unload
|
45
45
|
end
|
46
46
|
|
47
|
-
it "
|
47
|
+
it "should work with namespaced constants" do
|
48
48
|
Thingy::Whatsit.in_scope.should.be.true
|
49
49
|
Thingy::Whatsit::Critter.outside_scope.should.be.true
|
50
50
|
Thingy::Whatsit::Critter.new.instance.should.be.true
|
data/test/helpers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dyoder-autocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Yoder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,8 +36,14 @@ files:
|
|
36
36
|
- test/autoload.rb
|
37
37
|
- test/helpers.rb
|
38
38
|
- test/test_lib
|
39
|
+
- test/test_lib/answer42_it_is.rb
|
39
40
|
- test/test_lib/critter.rb
|
40
41
|
- test/test_lib/doo_dad.rb
|
42
|
+
- test/test_lib/humbug.rb
|
43
|
+
- test/test_lib/the_class42_gang.rb
|
44
|
+
- test/test_lib/the_one_and_only_class.rb
|
45
|
+
- test/test_lib/the_one_and_only_module.rb
|
46
|
+
- test/test_lib/the_pretender.rb
|
41
47
|
has_rdoc: true
|
42
48
|
homepage: http://dev.zeraweb.com/
|
43
49
|
post_install_message:
|