bunraku 3.0.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/Manifest.txt +39 -0
- data/README.txt +25 -0
- data/Rakefile +93 -0
- data/examples/corechain.rb +46 -0
- data/examples/person.rb +67 -0
- data/examples/person2.rb +62 -0
- data/examples/person3.rb +72 -0
- data/examples/rentalshop.rb +127 -0
- data/examples/requires.rb +50 -0
- data/examples/scope.rb +63 -0
- data/hacks/add_method_by_method_of_Class.rb +18 -0
- data/hacks/add_method_to_Class.rb +12 -0
- data/hacks/add_method_with_local_context.rb +27 -0
- data/hacks/anonymous_method.rb +37 -0
- data/hacks/class_creation_events.rb +45 -0
- data/hacks/get_nested_class.rb +22 -0
- data/hacks/hook_method.rb +50 -0
- data/hacks/method_missing_chain.rb +33 -0
- data/hacks/method_missing_chain_override.rb +39 -0
- data/hacks/pluralize.rb +24 -0
- data/lib/bunraku.rb +3 -0
- data/lib/bunraku/base.rb +9 -0
- data/lib/bunraku/class_ext.rb +37 -0
- data/lib/bunraku/core.rb +257 -0
- data/lib/bunraku/exceptions.rb +10 -0
- data/lib/bunraku/proxies.rb +121 -0
- data/lib/bunraku/utils.rb +21 -0
- data/lib/bunraku/version.rb +9 -0
- data/scripts/makemanifest.rb +20 -0
- data/scripts/uproadwebsite.sh +18 -0
- data/setup.rb +1585 -0
- data/spec/def_context_spec.rb +34 -0
- data/spec/interaction_spec.rb +127 -0
- data/spec/require_spec.rb +44 -0
- data/spec/role2_spec.rb +116 -0
- data/spec/role_spec.rb +120 -0
- data/test/test_bunraku.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/website/index.html +13 -0
- metadata +94 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
require "bunraku"
|
3
|
+
|
4
|
+
describe "Bunraku Context Def" do
|
5
|
+
it "should have no roles" do
|
6
|
+
Module.new {
|
7
|
+
context :MyContext do
|
8
|
+
end
|
9
|
+
c = const_get(:MyContext).new
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a role" do
|
14
|
+
Module.new {
|
15
|
+
context :MyContext do
|
16
|
+
role :MyRole1 do
|
17
|
+
end
|
18
|
+
end
|
19
|
+
c = const_get(:MyContext).new
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have roles" do
|
24
|
+
Module.new {
|
25
|
+
context :MyContext do
|
26
|
+
role :MyRole1 do
|
27
|
+
end
|
28
|
+
role :MyRole2 do
|
29
|
+
end
|
30
|
+
end
|
31
|
+
c = const_get(:MyContext).new
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
module InteractionSpec
|
3
|
+
class Equality
|
4
|
+
as_context
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@busy = false
|
8
|
+
end
|
9
|
+
attr_accessor :busy
|
10
|
+
|
11
|
+
class ActorA
|
12
|
+
as_role
|
13
|
+
def fire
|
14
|
+
core.fire()
|
15
|
+
unless context.busy
|
16
|
+
context.busy = true
|
17
|
+
context.ActorBs.fire
|
18
|
+
context.busy = false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
override :fire
|
22
|
+
end
|
23
|
+
class ActorB
|
24
|
+
as_role
|
25
|
+
def fire
|
26
|
+
core.fire()
|
27
|
+
unless context.busy
|
28
|
+
context.busy = true
|
29
|
+
context.ActorAs.fire
|
30
|
+
context.busy = false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
override :fire
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Trigger
|
38
|
+
as_context
|
39
|
+
class ActorA
|
40
|
+
as_role
|
41
|
+
def fire
|
42
|
+
core.fire()
|
43
|
+
context.ActorBs.fire
|
44
|
+
end
|
45
|
+
override :fire
|
46
|
+
end
|
47
|
+
class ActorB
|
48
|
+
as_role
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Core
|
53
|
+
def initialize
|
54
|
+
@fired = false
|
55
|
+
end
|
56
|
+
def fire
|
57
|
+
@fired = true
|
58
|
+
end
|
59
|
+
def fired?
|
60
|
+
@fired
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "Single Equality" do
|
66
|
+
before do
|
67
|
+
# core1 <-> core2
|
68
|
+
@equality = InteractionSpec::Equality.new
|
69
|
+
@core1 = InteractionSpec::Core.new
|
70
|
+
@core2 = InteractionSpec::Core.new
|
71
|
+
@equality.ActorA.bind(@core1)
|
72
|
+
@equality.ActorB.bind(@core2)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be fired when ActorA fired" do
|
76
|
+
@core1.fire
|
77
|
+
@core1.should be_fired
|
78
|
+
@core2.should be_fired
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "Cycle Equality" do
|
83
|
+
before do
|
84
|
+
# core1 <-> core2 <-> core3 <-> core1
|
85
|
+
@equality1 = InteractionSpec::Equality.new
|
86
|
+
@equality2 = InteractionSpec::Equality.new
|
87
|
+
@equality3 = InteractionSpec::Equality.new
|
88
|
+
@core1 = InteractionSpec::Core.new
|
89
|
+
@core2 = InteractionSpec::Core.new
|
90
|
+
@core3 = InteractionSpec::Core.new
|
91
|
+
@equality1.ActorA.bind(@core1)
|
92
|
+
@equality1.ActorB.bind(@core2)
|
93
|
+
@equality2.ActorA.bind(@core2)
|
94
|
+
@equality2.ActorB.bind(@core3)
|
95
|
+
@equality2.ActorA.bind(@core3)
|
96
|
+
@equality2.ActorB.bind(@core1)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be fired when ActorA fired" do
|
100
|
+
@core1.fire
|
101
|
+
@core1.should be_fired
|
102
|
+
@core2.should be_fired
|
103
|
+
@core3.should be_fired
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "Part Equality" do
|
108
|
+
before do
|
109
|
+
# core1 <-> core2 <-> core3
|
110
|
+
@equality1 = InteractionSpec::Equality.new
|
111
|
+
@equality2 = InteractionSpec::Equality.new
|
112
|
+
@core1 = InteractionSpec::Core.new
|
113
|
+
@core2 = InteractionSpec::Core.new
|
114
|
+
@core3 = InteractionSpec::Core.new
|
115
|
+
@equality1.ActorA.bind(@core1)
|
116
|
+
@equality1.ActorB.bind(@core2)
|
117
|
+
@equality2.ActorA.bind(@core2)
|
118
|
+
@equality2.ActorB.bind(@core3)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be fired when ActorA fired" do
|
122
|
+
@core1.fire
|
123
|
+
@core1.should be_fired
|
124
|
+
@core2.should be_fired
|
125
|
+
# @core3.should be_fired
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "bunraku"
|
2
|
+
|
3
|
+
describe "Roles with requires" do
|
4
|
+
setup do
|
5
|
+
module RequiresSpec
|
6
|
+
class MyContext
|
7
|
+
as_context
|
8
|
+
class MyRole1
|
9
|
+
as_role
|
10
|
+
requires do |req|
|
11
|
+
req.method? "m1"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class MyRole2
|
15
|
+
as_role
|
16
|
+
def m2()
|
17
|
+
context.MyRole1.m1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should bind object when requirement passed" do
|
25
|
+
c = RequiresSpec::MyContext.new
|
26
|
+
o1 = Object.new
|
27
|
+
o2 = Object.new
|
28
|
+
def o1.m1()
|
29
|
+
"m1"
|
30
|
+
end
|
31
|
+
|
32
|
+
c.MyRole1.bind(o1)
|
33
|
+
c.MyRole2.bind(o2)
|
34
|
+
o2.m2().should == "m1"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not bind object when requirement not passed " do
|
38
|
+
c = RequiresSpec::MyContext.new
|
39
|
+
o1 = Object.new
|
40
|
+
proc {
|
41
|
+
c.MyRole1.bind(o1)
|
42
|
+
}.should raise_error(Bunraku::BindRoleError)
|
43
|
+
end
|
44
|
+
end
|
data/spec/role2_spec.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "bunraku"
|
2
|
+
|
3
|
+
module Roles2Spec
|
4
|
+
class Human
|
5
|
+
def initialize name
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
attr :name
|
9
|
+
end
|
10
|
+
|
11
|
+
context :City do
|
12
|
+
role :Civilian do
|
13
|
+
def declare()
|
14
|
+
name + " dime"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
role :Gatherer do
|
19
|
+
def gather
|
20
|
+
context.Civilian.declare
|
21
|
+
end
|
22
|
+
def gather_all
|
23
|
+
context.Civilians.declare
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe "Civilian2", :shared => true do
|
31
|
+
it "should declare tax" do
|
32
|
+
@first_civilian.declare.should == "A dime"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "Gatherer2", :shared => true do
|
37
|
+
it "should gather tax from the first civilian" do
|
38
|
+
@gatherer.gather.should == "A dime"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should gather tax from all civilians" do
|
42
|
+
@gatherer.gather_all.should == @all_taxes
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
describe "City2 that has a Civilian" do
|
48
|
+
before do
|
49
|
+
@city = Roles2Spec::City.new
|
50
|
+
@first_civilian = Roles2Spec::Human.new "A"
|
51
|
+
@city.Civilian.bind(@first_civilian)
|
52
|
+
|
53
|
+
@all_taxes = ["A dime"]
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like "Civilian2"
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "City2, that has a Civilian and a Gatherer," do
|
60
|
+
before do
|
61
|
+
@city = Roles2Spec::City.new
|
62
|
+
@first_civilian = Roles2Spec::Human.new "A"
|
63
|
+
@city.Civilian.bind(@first_civilian)
|
64
|
+
@gatherer = Roles2Spec::Human.new "G"
|
65
|
+
@city.Gatherer.bind(@gatherer)
|
66
|
+
|
67
|
+
@all_taxes = ["A dime"]
|
68
|
+
end
|
69
|
+
|
70
|
+
it_should_behave_like "Civilian2"
|
71
|
+
it_should_behave_like "Gatherer2"
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "City2, that has Civilians and a Gatherer," do
|
75
|
+
before do
|
76
|
+
@city = Roles2Spec::City.new
|
77
|
+
@first_civilian = Roles2Spec::Human.new "A"
|
78
|
+
@city.Civilian.bind(@first_civilian)
|
79
|
+
@second_civilian = Roles2Spec::Human.new "B"
|
80
|
+
@city.Civilian.bind(@second_civilian)
|
81
|
+
@third_civilian = Roles2Spec::Human.new "C"
|
82
|
+
@city.Civilian.bind(@third_civilian)
|
83
|
+
@gatherer = Roles2Spec::Human.new "G"
|
84
|
+
@city.Gatherer.bind(@gatherer)
|
85
|
+
|
86
|
+
@all_taxes = ["A dime", "B dime", "C dime"]
|
87
|
+
end
|
88
|
+
|
89
|
+
it_should_behave_like "Civilian2"
|
90
|
+
it_should_behave_like "Gatherer2"
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
describe "City2, that has Civilians and a Gatherer who is also Civilian," do
|
96
|
+
before do
|
97
|
+
@city = Roles2Spec::City.new
|
98
|
+
@first_civilian = Roles2Spec::Human.new "A"
|
99
|
+
@city.Civilian.bind(@first_civilian)
|
100
|
+
@second_civilian = Roles2Spec::Human.new "B"
|
101
|
+
@city.Civilian.bind(@second_civilian)
|
102
|
+
@third_civilian = Roles2Spec::Human.new "C"
|
103
|
+
@city.Civilian.bind(@third_civilian)
|
104
|
+
@gatherer = Roles2Spec::Human.new "G"
|
105
|
+
@city.Civilian.bind(@gatherer)
|
106
|
+
@city.Gatherer.bind(@gatherer)
|
107
|
+
|
108
|
+
@all_taxes = ["A dime", "B dime", "C dime", "G dime"]
|
109
|
+
end
|
110
|
+
|
111
|
+
it_should_behave_like "Civilian2"
|
112
|
+
it_should_behave_like "Gatherer2"
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
data/spec/role_spec.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require "bunraku"
|
2
|
+
|
3
|
+
module RolesSpec
|
4
|
+
class Human
|
5
|
+
def initialize name
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
attr :name
|
9
|
+
end
|
10
|
+
|
11
|
+
class City
|
12
|
+
as_context
|
13
|
+
|
14
|
+
class Civilian
|
15
|
+
as_role
|
16
|
+
def declare()
|
17
|
+
name + " dime"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Gatherer
|
22
|
+
as_role
|
23
|
+
def gather
|
24
|
+
context.Civilian.declare
|
25
|
+
end
|
26
|
+
def gather_all
|
27
|
+
context.Civilians.declare
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe "Civilian", :shared => true do
|
35
|
+
it "should declare tax" do
|
36
|
+
@first_civilian.declare.should == "A dime"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Gatherer", :shared => true do
|
41
|
+
it "should gather tax from the first civilian" do
|
42
|
+
@gatherer.gather.should == "A dime"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should gather tax from all civilians" do
|
46
|
+
@gatherer.gather_all.should == @all_taxes
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "City that has a Civilian" do
|
52
|
+
before do
|
53
|
+
@city = RolesSpec::City.new
|
54
|
+
@first_civilian = RolesSpec::Human.new "A"
|
55
|
+
@city.Civilian.bind(@first_civilian)
|
56
|
+
|
57
|
+
@all_taxes = ["A dime"]
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like "Civilian"
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "City, that has a Civilian and a Gatherer," do
|
64
|
+
before do
|
65
|
+
@city = RolesSpec::City.new
|
66
|
+
@first_civilian = RolesSpec::Human.new "A"
|
67
|
+
@city.Civilian.bind(@first_civilian)
|
68
|
+
@gatherer = RolesSpec::Human.new "G"
|
69
|
+
@city.Gatherer.bind(@gatherer)
|
70
|
+
|
71
|
+
@all_taxes = ["A dime"]
|
72
|
+
end
|
73
|
+
|
74
|
+
it_should_behave_like "Civilian"
|
75
|
+
it_should_behave_like "Gatherer"
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "City, that has Civilians and a Gatherer," do
|
79
|
+
before do
|
80
|
+
@city = RolesSpec::City.new
|
81
|
+
@first_civilian = RolesSpec::Human.new "A"
|
82
|
+
@city.Civilian.bind(@first_civilian)
|
83
|
+
@second_civilian = RolesSpec::Human.new "B"
|
84
|
+
@city.Civilian.bind(@second_civilian)
|
85
|
+
@third_civilian = RolesSpec::Human.new "C"
|
86
|
+
@city.Civilian.bind(@third_civilian)
|
87
|
+
@gatherer = RolesSpec::Human.new "G"
|
88
|
+
@city.Gatherer.bind(@gatherer)
|
89
|
+
|
90
|
+
@all_taxes = ["A dime", "B dime", "C dime"]
|
91
|
+
end
|
92
|
+
|
93
|
+
it_should_behave_like "Civilian"
|
94
|
+
it_should_behave_like "Gatherer"
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
describe "City, that has Civilians and a Gatherer who is also Civilian," do
|
100
|
+
before do
|
101
|
+
@city = RolesSpec::City.new
|
102
|
+
@first_civilian = RolesSpec::Human.new "A"
|
103
|
+
@city.Civilian.bind(@first_civilian)
|
104
|
+
@second_civilian = RolesSpec::Human.new "B"
|
105
|
+
@city.Civilian.bind(@second_civilian)
|
106
|
+
@third_civilian = RolesSpec::Human.new "C"
|
107
|
+
@city.Civilian.bind(@third_civilian)
|
108
|
+
@gatherer = RolesSpec::Human.new "G"
|
109
|
+
@city.Civilian.bind(@gatherer)
|
110
|
+
@city.Gatherer.bind(@gatherer)
|
111
|
+
|
112
|
+
@all_taxes = ["A dime", "B dime", "C dime", "G dime"]
|
113
|
+
end
|
114
|
+
|
115
|
+
it_should_behave_like "Civilian"
|
116
|
+
it_should_behave_like "Gatherer"
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|