cascading_classes 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +165 -64
- data/spec/basics/basic_spec.rb +71 -76
- data/spec/basics/block_spec.rb +10 -10
- data/spec/basics/container_spec.rb +90 -90
- data/spec/basics/inherit_spec.rb +156 -156
- data/spec/basics/proc_spec.rb +94 -94
- data/spec/class_helper_methods/parents_for_spec.rb +5 -5
- data/spec/custom_classes/hash_like_spec.rb +11 -11
- data/spec/helper_spec.rb +11 -11
- data/spec/instances/basics.rb +39 -39
- data/spec/preset_classes/array_spec.rb +39 -39
- data/spec/preset_classes/hash_spec.rb +38 -38
- data/spec/preset_classes/strings.rb +53 -53
- data/spec/preset_classes/undefined.rb +4 -4
- data/spec/usage/block_spec.rb +6 -6
- data/spec/usage/proc_spec.rb +8 -8
- data/todo +21 -0
- metadata +1 -2
- data/README-part-ii.md +0 -1020
@@ -27,50 +27,50 @@ describe "array syntax" do
|
|
27
27
|
|
28
28
|
props = Parent.singleton_class.properties
|
29
29
|
|
30
|
-
props[:colors_a][:type].
|
31
|
-
props[:colors_b][:type].
|
32
|
-
props[:colors_c][:type].
|
33
|
-
Parent.colors_a.
|
34
|
-
Parent.colors_b.
|
35
|
-
Parent.colors_c.
|
30
|
+
props[:colors_a][:type].should == :Array
|
31
|
+
props[:colors_b][:type].should == :Array
|
32
|
+
props[:colors_c][:type].should == :undefined_type
|
33
|
+
Parent.colors_a.should == [:red, :blue, :yellow]
|
34
|
+
Parent.colors_b.should == []
|
35
|
+
Parent.colors_c.should == nil
|
36
36
|
|
37
37
|
Parent.colors_b << :red << :blue << :yellow
|
38
38
|
Parent.colors_c = [:red, :blue, :yellow]
|
39
39
|
|
40
|
-
props[:colors_c][:type].
|
41
|
-
Parent.colors_b.
|
42
|
-
Parent.colors_c.
|
40
|
+
props[:colors_c][:type].should == :Array
|
41
|
+
Parent.colors_b.should == [:red, :blue, :yellow]
|
42
|
+
Parent.colors_c.should == [:red, :blue, :yellow]
|
43
43
|
|
44
44
|
Parent.cascade [:colors_d, [:red, :blue, :yellow]], :colors_e
|
45
45
|
Parent.cascade [:colors_f, [:red, :blue, :yellow]]
|
46
46
|
Parent.cascade :colors_g
|
47
47
|
|
48
|
-
props[:colors_d][:type].
|
49
|
-
props[:colors_e][:type].
|
50
|
-
props[:colors_f][:type].
|
51
|
-
props[:colors_g][:type].
|
52
|
-
Parent.colors_d.
|
53
|
-
Parent.colors_e.
|
54
|
-
Parent.colors_f.
|
55
|
-
Parent.colors_g.
|
48
|
+
props[:colors_d][:type].should == :Array
|
49
|
+
props[:colors_e][:type].should == :undefined_type
|
50
|
+
props[:colors_f][:type].should == :Array
|
51
|
+
props[:colors_g][:type].should == :undefined_type
|
52
|
+
Parent.colors_d.should == [:red, :blue, :yellow]
|
53
|
+
Parent.colors_e.should == nil
|
54
|
+
Parent.colors_f.should == [:red, :blue, :yellow]
|
55
|
+
Parent.colors_g.should == nil
|
56
56
|
|
57
57
|
Parent.colors_e = [:red, :blue, :yellow]
|
58
58
|
Parent.colors_g = [:red, :blue, :yellow]
|
59
59
|
|
60
|
-
props[:colors_e][:type].
|
61
|
-
props[:colors_g][:type].
|
62
|
-
Parent.colors_e.
|
63
|
-
Parent.colors_g.
|
60
|
+
props[:colors_e][:type].should == :Array
|
61
|
+
props[:colors_g][:type].should == :Array
|
62
|
+
Parent.colors_e.should == [:red, :blue, :yellow]
|
63
|
+
Parent.colors_g.should == [:red, :blue, :yellow]
|
64
64
|
end
|
65
65
|
|
66
66
|
it "is all the same" do
|
67
|
-
Parent.colors_a.
|
68
|
-
Parent.colors_b.
|
69
|
-
Parent.colors_c.
|
70
|
-
Parent.colors_d.
|
71
|
-
Parent.colors_e.
|
72
|
-
Parent.colors_f.
|
73
|
-
Parent.colors_g.
|
67
|
+
Parent.colors_a.should == [:red, :blue, :yellow]
|
68
|
+
Parent.colors_b.should == [:red, :blue, :yellow]
|
69
|
+
Parent.colors_c.should == [:red, :blue, :yellow]
|
70
|
+
Parent.colors_d.should == [:red, :blue, :yellow]
|
71
|
+
Parent.colors_e.should == [:red, :blue, :yellow]
|
72
|
+
Parent.colors_f.should == [:red, :blue, :yellow]
|
73
|
+
Parent.colors_g.should == [:red, :blue, :yellow]
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -94,32 +94,32 @@ describe "array syntax" do
|
|
94
94
|
|
95
95
|
describe "by default" do
|
96
96
|
it "is set to not 'inherit' by default" do
|
97
|
-
@props[:fruit][:inherit].
|
98
|
-
Child.fruit.
|
97
|
+
@props[:fruit][:inherit].should ==(false)
|
98
|
+
Child.fruit.should == []
|
99
99
|
end
|
100
100
|
|
101
101
|
it "descendents (including instances) do not inherit" do
|
102
|
-
Parent.new.fruit.
|
103
|
-
Child.fruit.
|
104
|
-
Child.new.fruit.
|
105
|
-
GrandChild.fruit.
|
106
|
-
GrandChild.new.fruit.
|
102
|
+
Parent.new.fruit.should == []
|
103
|
+
Child.fruit.should == []
|
104
|
+
Child.new.fruit.should == []
|
105
|
+
GrandChild.fruit.should == []
|
106
|
+
GrandChild.new.fruit.should == []
|
107
107
|
end
|
108
108
|
|
109
109
|
it "'Parent' has default value" do
|
110
|
-
Parent.fruit.
|
110
|
+
Parent.fruit.should == [:orange, :apple, :pear]
|
111
111
|
end
|
112
112
|
|
113
113
|
it "has type ':Array'" do
|
114
|
-
@props[:fruit][:type].
|
114
|
+
@props[:fruit][:type].should == :Array
|
115
115
|
end
|
116
116
|
|
117
117
|
it "has blank value of empty array" do
|
118
|
-
@props[:fruit][:blank].call([]).
|
118
|
+
@props[:fruit][:blank].call([]).should == true
|
119
119
|
end
|
120
120
|
|
121
121
|
it "has new value of empty array" do
|
122
|
-
@props[:fruit][:new].call.
|
122
|
+
@props[:fruit][:new].call.should == []
|
123
123
|
end
|
124
124
|
|
125
125
|
it "nonblank values never inherit" do
|
@@ -29,46 +29,46 @@ describe "hash syntax" do
|
|
29
29
|
|
30
30
|
props = Parent.singleton_class.properties
|
31
31
|
|
32
|
-
props[:person_a][:type].
|
33
|
-
props[:person_b][:type].
|
34
|
-
props[:person_c][:type].
|
35
|
-
Parent.person_a.
|
36
|
-
Parent.person_b.
|
37
|
-
Parent.person_c.
|
32
|
+
props[:person_a][:type].should == :Hash
|
33
|
+
props[:person_b][:type].should == :Hash
|
34
|
+
props[:person_c][:type].should == :undefined_type
|
35
|
+
Parent.person_a.should ==({:name => ['williamson', 'charles']})
|
36
|
+
Parent.person_b.should ==({})
|
37
|
+
Parent.person_c.should == nil
|
38
38
|
|
39
39
|
Parent.person_b[:name] = ['williamson', 'charles']
|
40
40
|
Parent.person_c = {:name => ['williamson', 'charles']}
|
41
|
-
props[:person_c][:type].
|
42
|
-
Parent.person_b.
|
43
|
-
Parent.person_c.
|
41
|
+
props[:person_c][:type].should == :Hash
|
42
|
+
Parent.person_b.should ==({:name => ['williamson', 'charles']})
|
43
|
+
Parent.person_c.should ==({:name => ['williamson', 'charles']})
|
44
44
|
|
45
45
|
Parent.cascade [:person_d, {:name => ['williamson', 'charles']}], :person_e
|
46
46
|
Parent.cascade [:person_f, {:name => ['williamson', 'charles']}]
|
47
47
|
Parent.cascade :person_g
|
48
|
-
props[:person_d][:type].
|
49
|
-
props[:person_e][:type].
|
50
|
-
props[:person_f][:type].
|
51
|
-
props[:person_g][:type].
|
52
|
-
Parent.person_d.
|
53
|
-
Parent.person_e.
|
54
|
-
Parent.person_f.
|
55
|
-
Parent.person_g.
|
48
|
+
props[:person_d][:type].should == :Hash
|
49
|
+
props[:person_e][:type].should == :undefined_type
|
50
|
+
props[:person_f][:type].should == :Hash
|
51
|
+
props[:person_g][:type].should == :undefined_type
|
52
|
+
Parent.person_d.should ==({:name => ['williamson', 'charles']})
|
53
|
+
Parent.person_e.should == nil
|
54
|
+
Parent.person_f.should ==({:name => ['williamson', 'charles']})
|
55
|
+
Parent.person_g.should == nil
|
56
56
|
|
57
57
|
Parent.person_e = Parent.person_g = {:name => ['williamson', 'charles']}
|
58
|
-
props[:person_e][:type].
|
59
|
-
props[:person_g][:type].
|
60
|
-
Parent.person_e.
|
61
|
-
Parent.person_g.
|
58
|
+
props[:person_e][:type].should == :Hash
|
59
|
+
props[:person_g][:type].should == :Hash
|
60
|
+
Parent.person_e.should ==({:name => ['williamson', 'charles']})
|
61
|
+
Parent.person_g.should ==({:name => ['williamson', 'charles']})
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'is all the same' do
|
65
|
-
Parent.person_a.
|
66
|
-
Parent.person_b.
|
67
|
-
Parent.person_c.
|
68
|
-
Parent.person_d.
|
69
|
-
Parent.person_e.
|
70
|
-
Parent.person_f.
|
71
|
-
Parent.person_g.
|
65
|
+
Parent.person_a.should ==({:name => ['williamson', 'charles']})
|
66
|
+
Parent.person_b.should ==({:name => ['williamson', 'charles']})
|
67
|
+
Parent.person_c.should ==({:name => ['williamson', 'charles']})
|
68
|
+
Parent.person_d.should ==({:name => ['williamson', 'charles']})
|
69
|
+
Parent.person_e.should ==({:name => ['williamson', 'charles']})
|
70
|
+
Parent.person_f.should ==({:name => ['williamson', 'charles']})
|
71
|
+
Parent.person_g.should ==({:name => ['williamson', 'charles']})
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -92,31 +92,31 @@ describe "hash usage" do
|
|
92
92
|
|
93
93
|
describe "by default" do
|
94
94
|
it "is set to not 'inherit' by default" do
|
95
|
-
@props[:eyes][:inherit].
|
95
|
+
@props[:eyes][:inherit].should == false
|
96
96
|
end
|
97
97
|
|
98
98
|
it "descendents (including instances) do not inherit" do
|
99
|
-
Parent.new.eyes.
|
100
|
-
Child.eyes.
|
101
|
-
Child.new.eyes.
|
102
|
-
GrandChild.eyes.
|
103
|
-
GrandChild.new.eyes.
|
99
|
+
Parent.new.eyes.should ==({})
|
100
|
+
Child.eyes.should ==({})
|
101
|
+
Child.new.eyes.should ==({})
|
102
|
+
GrandChild.eyes.should ==({})
|
103
|
+
GrandChild.new.eyes.should ==({})
|
104
104
|
end
|
105
105
|
|
106
106
|
it "'Parent' has 'default' value" do
|
107
|
-
Parent.eyes.
|
107
|
+
Parent.eyes.should ==({:color => "red"})
|
108
108
|
end
|
109
109
|
|
110
110
|
it "has type ':Hash'" do
|
111
|
-
@props[:eyes][:type].
|
111
|
+
@props[:eyes][:type].should == :Hash
|
112
112
|
end
|
113
113
|
|
114
114
|
it "has blank value of empty hash" do
|
115
|
-
@props[:eyes][:blank].call({}).
|
115
|
+
@props[:eyes][:blank].call({}).should == true
|
116
116
|
end
|
117
117
|
|
118
118
|
it "has new value of empty hash" do
|
119
|
-
@props[:eyes][:new].call.
|
119
|
+
@props[:eyes][:new].call.should ==({})
|
120
120
|
end
|
121
121
|
|
122
122
|
it "nonblank values never inherit" do
|
@@ -27,46 +27,46 @@ describe "string - base" do
|
|
27
27
|
|
28
28
|
props = Parent.singleton_class.properties
|
29
29
|
|
30
|
-
props[:color_a][:type].
|
31
|
-
props[:color_b][:type].
|
32
|
-
props[:color_c][:type].
|
33
|
-
Parent.color_a.
|
34
|
-
Parent.color_b.
|
35
|
-
Parent.color_c.
|
30
|
+
props[:color_a][:type].should == :String
|
31
|
+
props[:color_b][:type].should == :String
|
32
|
+
props[:color_c][:type].should == :Object
|
33
|
+
Parent.color_a.should == "white"
|
34
|
+
Parent.color_b.should == ''
|
35
|
+
Parent.color_c.should == nil
|
36
36
|
|
37
37
|
Parent.color_b = "white"
|
38
38
|
Parent.color_c = "white"
|
39
|
-
props[:color_c][:type].
|
40
|
-
Parent.color_b.
|
41
|
-
Parent.color_c.
|
39
|
+
props[:color_c][:type].should == :String
|
40
|
+
Parent.color_b.should == "white"
|
41
|
+
Parent.color_c.should == "white"
|
42
42
|
|
43
43
|
Parent.cascade [:color_d, "white"], :color_e
|
44
44
|
Parent.cascade [:color_f, "white"]
|
45
45
|
Parent.cascade :color_g
|
46
|
-
props[:color_d][:type].
|
47
|
-
props[:color_e][:type].
|
48
|
-
props[:color_f][:type].
|
49
|
-
props[:color_g][:type].
|
50
|
-
Parent.color_d.
|
51
|
-
Parent.color_e.
|
52
|
-
Parent.color_f.
|
53
|
-
Parent.color_g.
|
46
|
+
props[:color_d][:type].should == :String
|
47
|
+
props[:color_e][:type].should == :Object
|
48
|
+
props[:color_f][:type].should == :String
|
49
|
+
props[:color_g][:type].should == :Object
|
50
|
+
Parent.color_d.should == "white"
|
51
|
+
Parent.color_e.should == nil
|
52
|
+
Parent.color_f.should == "white"
|
53
|
+
Parent.color_g.should == nil
|
54
54
|
|
55
55
|
Parent.color_e = Parent.color_g = "white"
|
56
|
-
props[:color_e][:type].
|
57
|
-
props[:color_g][:type].
|
58
|
-
Parent.color_e.
|
59
|
-
Parent.color_g.
|
56
|
+
props[:color_e][:type].should == :String
|
57
|
+
props[:color_g][:type].should == :String
|
58
|
+
Parent.color_e.should == "white"
|
59
|
+
Parent.color_g.should == "white"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "is all the same" do
|
63
|
-
Parent.color_a.
|
64
|
-
Parent.color_b.
|
65
|
-
Parent.color_c.
|
66
|
-
Parent.color_d.
|
67
|
-
Parent.color_e.
|
68
|
-
Parent.color_f.
|
69
|
-
Parent.color_g.
|
63
|
+
Parent.color_a.should == "white"
|
64
|
+
Parent.color_b.should == "white"
|
65
|
+
Parent.color_c.should == "white"
|
66
|
+
Parent.color_d.should == "white"
|
67
|
+
Parent.color_e.should == "white"
|
68
|
+
Parent.color_f.should == "white"
|
69
|
+
Parent.color_g.should == "white"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -90,19 +90,19 @@ describe "string" do
|
|
90
90
|
|
91
91
|
describe "by default" do
|
92
92
|
it "has type :String" do
|
93
|
-
@props[:color][:type].
|
93
|
+
@props[:color][:type].should == :String
|
94
94
|
end
|
95
95
|
|
96
96
|
it "inherits by default" do
|
97
|
-
@props[:color][:inherit].
|
97
|
+
@props[:color][:inherit].should == true
|
98
98
|
end
|
99
99
|
|
100
100
|
it "has blank value of empty string" do
|
101
|
-
@props[:color][:blank].call('').
|
101
|
+
@props[:color][:blank].call('').should == true
|
102
102
|
end
|
103
103
|
|
104
104
|
it "has new value of empty string" do
|
105
|
-
@props[:color][:new].call.
|
105
|
+
@props[:color][:new].call.should == ''
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -142,29 +142,29 @@ describe "string" do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "has blank value of nil and new value of empty string" do
|
145
|
-
@props[:city][:blank].call('').
|
146
|
-
@props[:city][:blank].call(nil).
|
145
|
+
@props[:city][:blank].call('').should == false
|
146
|
+
@props[:city][:blank].call(nil).should == true
|
147
147
|
|
148
148
|
new_val = @props[:city][:new].call
|
149
149
|
|
150
|
-
Parent.city.
|
151
|
-
Parent.city_is_blank?.
|
152
|
-
Child.city.
|
153
|
-
Child.city_is_blank?.
|
154
|
-
GrandChild.city.
|
155
|
-
GrandChild.city_is_blank?.
|
150
|
+
Parent.city.should == "new york"
|
151
|
+
Parent.city_is_blank?.should == false
|
152
|
+
Child.city.should == new_val
|
153
|
+
Child.city_is_blank?.should == false
|
154
|
+
GrandChild.city.should == new_val
|
155
|
+
GrandChild.city_is_blank?.should == false
|
156
156
|
|
157
157
|
GrandChild.city = nil
|
158
|
-
GrandChild.city_is_blank?.
|
159
|
-
GrandChild.city.
|
158
|
+
GrandChild.city_is_blank?.should == true
|
159
|
+
GrandChild.city.should == Child.city
|
160
160
|
|
161
161
|
Child.city = nil
|
162
|
-
Child.city_is_blank?.
|
163
|
-
Child.city.
|
162
|
+
Child.city_is_blank?.should == true
|
163
|
+
Child.city.should == Parent.city
|
164
164
|
|
165
165
|
Parent.city = nil
|
166
|
-
Parent.city.
|
167
|
-
Parent.city_is_blank?.
|
166
|
+
Parent.city.should == nil
|
167
|
+
Parent.city_is_blank?.should == true
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -176,15 +176,15 @@ describe "string" do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "has blank value of nil and new value of nil" do
|
179
|
-
@props[:state][:blank].call('').
|
180
|
-
@props[:state][:blank].call(nil).
|
181
|
-
@props[:state][:new].call.
|
179
|
+
@props[:state][:blank].call('').should == false
|
180
|
+
@props[:state][:blank].call(nil).should == true
|
181
|
+
@props[:state][:new].call.should == nil
|
182
182
|
|
183
|
-
Child.state_is_blank?.
|
184
|
-
GrandChild.state_is_blank?.
|
183
|
+
Child.state_is_blank?.should == true
|
184
|
+
GrandChild.state_is_blank?.should == true
|
185
185
|
|
186
|
-
Child.state(false).
|
187
|
-
GrandChild.state(false).
|
186
|
+
Child.state(false).should == nil
|
187
|
+
GrandChild.state(false).should == nil
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
@@ -34,22 +34,22 @@ describe "null syntax" do
|
|
34
34
|
it "has ':Object' type" do
|
35
35
|
[:string, :int, :float, :sym, :bool, :hash, :array, :set].each do |type|
|
36
36
|
name = "future_#{type}".to_sym
|
37
|
-
@props[name][:type].
|
37
|
+
@props[name][:type].should == :Object
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
it "is nil for parent class" do
|
42
42
|
[:string, :int, :float, :sym, :bool, :hash, :array, :set].each do |type|
|
43
43
|
name = "future_#{type}".to_sym
|
44
|
-
Parent.send(name).
|
44
|
+
Parent.send(name).should == nil
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
it "is nil for subclasses" do
|
49
49
|
[:string, :int, :float, :sym, :bool, :hash, :array, :set].each do |type|
|
50
50
|
name = "future_#{type}".to_sym
|
51
|
-
Child.send(name).
|
52
|
-
GrandChild.send(name).
|
51
|
+
Child.send(name).should == nil
|
52
|
+
GrandChild.send(name).should == nil
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/spec/usage/block_spec.rb
CHANGED
@@ -21,17 +21,17 @@ describe "options" do
|
|
21
21
|
|
22
22
|
it "has a global default" do
|
23
23
|
CC.block_inst_exec = true
|
24
|
-
CC.block_inst_exec?.
|
24
|
+
CC.block_inst_exec?.should == true
|
25
25
|
|
26
26
|
CC.block_inst_exec = false
|
27
|
-
CC.block_inst_exec?.
|
27
|
+
CC.block_inst_exec?.should == false
|
28
28
|
end
|
29
29
|
|
30
30
|
it "defaults to global setting" do
|
31
31
|
props = A.cascade do
|
32
32
|
color
|
33
33
|
end
|
34
|
-
props[:color][:block_inst_exec].
|
34
|
+
props[:color][:block_inst_exec].should ==(CC.block_inst_exec?)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "can be set in the 'cascade' block, overruling the global default" do
|
@@ -39,7 +39,7 @@ describe "options" do
|
|
39
39
|
props = A.cascade do
|
40
40
|
color :block_inst_exec => false
|
41
41
|
end
|
42
|
-
props[:color][:block_inst_exec].
|
42
|
+
props[:color][:block_inst_exec].should == false
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can be set in 'opts' hash of property method, overruling others" do
|
@@ -52,8 +52,8 @@ describe "options" do
|
|
52
52
|
who_is_self_1 = A.color(:inherit, 0){|me, parents| self}
|
53
53
|
who_is_self_2 = A.color(:inherit, 0, {:block_inst_exec => true}){|me, parents| self}
|
54
54
|
|
55
|
-
who_is_self_1.
|
56
|
-
who_is_self_2.
|
55
|
+
who_is_self_1.should == who_am_i
|
56
|
+
who_is_self_2.should == A
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|