programmable-ventouse 0.0.10 → 0.1.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/lib/ventouse/module_declarations.rb +11 -7
- data/test/declarations_test.rb +77 -0
- metadata +4 -3
@@ -11,19 +11,23 @@ class Module
|
|
11
11
|
# end
|
12
12
|
# end
|
13
13
|
def declarations &blk
|
14
|
-
|
14
|
+
unless @declaration_blocks
|
15
|
+
@declaration_blocks = []
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def self.included mod
|
18
|
+
case mod
|
19
|
+
when Class
|
20
|
+
@declaration_blocks.each {|b| mod.class_eval &b }
|
21
|
+
when Module
|
22
|
+
@declaration_blocks.each {|b| mod.declarations &b }
|
23
|
+
end
|
21
24
|
rescue Exception => ex # When autoloading, you never see real exception unless this rescue
|
22
25
|
puts ex.message
|
23
26
|
puts ex.backtrace.join("\n")
|
24
27
|
raise ex
|
25
28
|
end
|
26
29
|
end
|
27
|
-
|
30
|
+
|
31
|
+
@declaration_blocks << blk
|
28
32
|
end
|
29
33
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../lib/ventouse/module_declarations"
|
3
|
+
|
4
|
+
module SmokeExt
|
5
|
+
declarations do
|
6
|
+
self.class_var= "ok"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module SecondExt
|
11
|
+
declarations do
|
12
|
+
self.class_var= "ok2"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module MultipleDeclarationsModule
|
17
|
+
declarations do
|
18
|
+
self.class_var= "x"
|
19
|
+
end
|
20
|
+
|
21
|
+
declarations do
|
22
|
+
self.class_var+= "x"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module IncludedModule
|
27
|
+
declarations do
|
28
|
+
self.class_var+= "y"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module IncludingModule
|
33
|
+
declarations do
|
34
|
+
self.class_var= "x"
|
35
|
+
end
|
36
|
+
|
37
|
+
include IncludedModule
|
38
|
+
|
39
|
+
declarations do
|
40
|
+
self.class_var+= "z"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class SmokeExpandable
|
45
|
+
def self.class_var= var
|
46
|
+
@@class_var = var
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.class_var
|
50
|
+
@@class_var if defined? @@class_var
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class DeclarationsTest < Test::Unit::TestCase
|
55
|
+
def test_smoke
|
56
|
+
SmokeExpandable.send :include, SmokeExt
|
57
|
+
assert_equal "ok", SmokeExpandable.class_var
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_second_module
|
61
|
+
SmokeExpandable.send :include, SmokeExt
|
62
|
+
assert_equal "ok", SmokeExpandable.class_var
|
63
|
+
|
64
|
+
SmokeExpandable.send :include, SecondExt
|
65
|
+
assert_equal "ok2", SmokeExpandable.class_var
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_multiple_declarations
|
69
|
+
SmokeExpandable.send :include, MultipleDeclarationsModule
|
70
|
+
assert_equal "xx", SmokeExpandable.class_var
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_module_including
|
74
|
+
SmokeExpandable.send :include, IncludingModule
|
75
|
+
assert_equal "xyz", SmokeExpandable.class_var
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: programmable-ventouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilia Ablamonov
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/ventouse/rescue_ext.rb
|
45
45
|
- lib/ventouse/resource_as_root.rb
|
46
46
|
- lib/ventouse.rb
|
47
|
+
- test/declarations_test.rb
|
47
48
|
has_rdoc: true
|
48
49
|
homepage: http://github.com/programmable/ventouse
|
49
50
|
licenses:
|
@@ -74,5 +75,5 @@ rubygems_version: 1.3.5
|
|
74
75
|
signing_key:
|
75
76
|
specification_version: 2
|
76
77
|
summary: Various usefull ruby/rails shit.
|
77
|
-
test_files:
|
78
|
-
|
78
|
+
test_files:
|
79
|
+
- test/declarations_test.rb
|