arrayfu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arrayfu/arrayfu.rb +13 -6
- data/lib/arrayfu/version.rb +1 -1
- data/spec/examples/usage.rb +39 -39
- data/spec/specs/dsl_usage_spec.rb +25 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b5a20091ff3fd52e2a31aa176d205ad90253a8
|
4
|
+
data.tar.gz: 38595e560fb27d9dabf1054d2611d01a04e6ed2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e87aa4a17062bec29f00791c4f5a35727757dc9bee1639ed2c17a967a69dc9426f16c6480d73c9f599aee7d98be1ea12b94338e2d4fe949a067c559979599fe
|
7
|
+
data.tar.gz: 583d5bbc51a7d8e44a24472fd3093ef53e9ca0fe6ea587b5007310fc4d0b28bd87ce7caac3242e77c8522759c0669f907d317f62c9bedd1209029b642c326f9f
|
data/lib/arrayfu/arrayfu.rb
CHANGED
@@ -12,20 +12,27 @@ module ArrayFu
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def array(name, &block)
|
16
|
+
self.class.array(name, &block)
|
17
|
+
end
|
18
|
+
|
15
19
|
module ClassMethods
|
16
20
|
def array_definitions
|
17
|
-
@array_definitions ||=
|
21
|
+
@array_definitions ||= {}
|
18
22
|
end
|
19
23
|
|
20
24
|
def each_array_definition(&block)
|
21
|
-
array_definitions.each &block
|
25
|
+
array_definitions.values.each &block
|
22
26
|
end
|
23
27
|
|
24
28
|
def array(name, &block)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
unless array_definitions.has_key?(name)
|
30
|
+
array_definition = ArrayDefinition.new(name)
|
31
|
+
array_definitions[name] = array_definition
|
32
|
+
end
|
33
|
+
definition = array_definitions[name]
|
34
|
+
definition.instance_eval(&block) if block_given?
|
35
|
+
definition
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
data/lib/arrayfu/version.rb
CHANGED
data/spec/examples/usage.rb
CHANGED
@@ -13,8 +13,8 @@ example 'Allow the array to have a read accessor' do
|
|
13
13
|
class SomeClass
|
14
14
|
include ArrayFu
|
15
15
|
|
16
|
-
array :names do
|
17
|
-
|
16
|
+
array :names do
|
17
|
+
readable
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize
|
@@ -29,8 +29,8 @@ example 'Allow the array to have a write accessor' do
|
|
29
29
|
class SomeClass
|
30
30
|
include ArrayFu
|
31
31
|
|
32
|
-
array :names do
|
33
|
-
|
32
|
+
array :names do
|
33
|
+
writable
|
34
34
|
end
|
35
35
|
|
36
36
|
def initialize
|
@@ -44,8 +44,8 @@ example 'Allow the array to have a read and write accessor' do
|
|
44
44
|
class SomeClass
|
45
45
|
include ArrayFu
|
46
46
|
|
47
|
-
array :names do
|
48
|
-
|
47
|
+
array :names do
|
48
|
+
read_and_write
|
49
49
|
end
|
50
50
|
|
51
51
|
def initialize
|
@@ -59,8 +59,8 @@ example 'Add a mutator method to the class that stores the array' do
|
|
59
59
|
class SomeClass
|
60
60
|
include ArrayFu
|
61
61
|
|
62
|
-
array :names do
|
63
|
-
|
62
|
+
array :names do
|
63
|
+
mutator :add_item
|
64
64
|
end
|
65
65
|
def initialize
|
66
66
|
initialize_arrayfu
|
@@ -76,8 +76,8 @@ example 'Add multiple mutators to the class that stores the array' do
|
|
76
76
|
class SomeClass
|
77
77
|
include ArrayFu
|
78
78
|
|
79
|
-
array :names do
|
80
|
-
|
79
|
+
array :names do
|
80
|
+
mutator :add_item, :add_it, :push_it
|
81
81
|
end
|
82
82
|
def initialize
|
83
83
|
initialize_arrayfu
|
@@ -96,8 +96,8 @@ example 'Add a mutator that ignores addition' do
|
|
96
96
|
class SomeClass
|
97
97
|
include ArrayFu
|
98
98
|
|
99
|
-
array :names do
|
100
|
-
|
99
|
+
array :names do
|
100
|
+
mutator :add_item do|item|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
def initialize
|
@@ -115,13 +115,13 @@ example 'Add a mutator that does other custom logic as well as addition' do
|
|
115
115
|
class SomeClass
|
116
116
|
include ArrayFu
|
117
117
|
|
118
|
-
array :secondary do
|
119
|
-
|
118
|
+
array :secondary do
|
119
|
+
readable
|
120
120
|
end
|
121
121
|
|
122
|
-
array :names do
|
123
|
-
|
124
|
-
|
122
|
+
array :names do
|
123
|
+
readable
|
124
|
+
mutator :add_item do|item|
|
125
125
|
@secondary.push item
|
126
126
|
@names.push item
|
127
127
|
end
|
@@ -162,9 +162,9 @@ example 'Add a singular constraint and failure condition to each of the mutators
|
|
162
162
|
class SomeClass
|
163
163
|
include ArrayFu
|
164
164
|
|
165
|
-
array :names do
|
166
|
-
|
167
|
-
|
165
|
+
array :names do
|
166
|
+
mutator :add_item,:add_it
|
167
|
+
new_item_must NotBeJP, CriteriaViolation
|
168
168
|
end
|
169
169
|
|
170
170
|
def initialize
|
@@ -214,10 +214,10 @@ example 'Add multiple constraints and a failure condition to each of the mutator
|
|
214
214
|
class SomeClass
|
215
215
|
include ArrayFu
|
216
216
|
|
217
|
-
array :names do
|
218
|
-
|
219
|
-
|
220
|
-
|
217
|
+
array :names do
|
218
|
+
mutator :add_item,:add_it
|
219
|
+
addition_constraint NotBeJP
|
220
|
+
addition_constraint NotBeNil, CriteriaViolation
|
221
221
|
end
|
222
222
|
|
223
223
|
def initialize
|
@@ -248,9 +248,9 @@ example 'Add an explicit processing visitor to the array' do
|
|
248
248
|
class SomeClass
|
249
249
|
include ArrayFu
|
250
250
|
|
251
|
-
array :names do
|
252
|
-
|
253
|
-
|
251
|
+
array :names do
|
252
|
+
mutator :add_item
|
253
|
+
process_using :display_all,DisplayItem
|
254
254
|
end
|
255
255
|
def initialize
|
256
256
|
initialize_arrayfu
|
@@ -275,9 +275,9 @@ example 'Add an method based processing visitor to the array based on a method t
|
|
275
275
|
@@items_visited = 0
|
276
276
|
include ArrayFu
|
277
277
|
|
278
|
-
array :names do
|
279
|
-
|
280
|
-
|
278
|
+
array :names do
|
279
|
+
mutator :add_item
|
280
|
+
process_using :display_all, :process #the second symbol is the name of a method on an element in the array
|
281
281
|
end
|
282
282
|
|
283
283
|
|
@@ -309,9 +309,9 @@ example 'Augment configuration using configuration block' do
|
|
309
309
|
class SomeClass
|
310
310
|
include ArrayFu
|
311
311
|
|
312
|
-
array :names do
|
313
|
-
|
314
|
-
|
312
|
+
array :names do
|
313
|
+
mutator :add_item
|
314
|
+
configure_using ArrayConfigs.add_another_mutator
|
315
315
|
end
|
316
316
|
|
317
317
|
def initialize
|
@@ -338,9 +338,9 @@ example 'Augment configuration using configuration instance (anything that respo
|
|
338
338
|
class SomeClass
|
339
339
|
include ArrayFu
|
340
340
|
|
341
|
-
array :names do
|
342
|
-
|
343
|
-
|
341
|
+
array :names do
|
342
|
+
mutator :add_item
|
343
|
+
configure_using ArrayConfiguration
|
344
344
|
end
|
345
345
|
|
346
346
|
def initialize
|
@@ -369,9 +369,9 @@ example 'Augment configuration using configuration block' do
|
|
369
369
|
class SomeClass
|
370
370
|
include ArrayFu
|
371
371
|
|
372
|
-
array :names do
|
373
|
-
|
374
|
-
|
372
|
+
array :names do
|
373
|
+
mutator :add_item
|
374
|
+
configure_using ArrayConfiguration.configuration_block
|
375
375
|
end
|
376
376
|
def initialize
|
377
377
|
initialize_arrayfu
|
@@ -7,9 +7,9 @@ module ArrayFu
|
|
7
7
|
class Item
|
8
8
|
include ArrayFu
|
9
9
|
|
10
|
-
array :kids do
|
11
|
-
|
12
|
-
|
10
|
+
array :kids do
|
11
|
+
readable
|
12
|
+
mutator :register_child
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize
|
@@ -27,9 +27,9 @@ module ArrayFu
|
|
27
27
|
include ArrayFu
|
28
28
|
attr_accessor :added,:item_added
|
29
29
|
|
30
|
-
array :kids do
|
31
|
-
|
32
|
-
|
30
|
+
array :kids do
|
31
|
+
readable
|
32
|
+
mutator :register_child do|the_item|
|
33
33
|
@item_added = the_item
|
34
34
|
@added +=1
|
35
35
|
@kids.push(the_item)
|
@@ -67,9 +67,9 @@ module ArrayFu
|
|
67
67
|
include ArrayFu
|
68
68
|
attr_accessor :added
|
69
69
|
|
70
|
-
array :kids do
|
71
|
-
|
72
|
-
|
70
|
+
array :kids do
|
71
|
+
mutator :register_child
|
72
|
+
process_using :register_kids, OurVisitor.instance
|
73
73
|
end
|
74
74
|
|
75
75
|
def initialize
|
@@ -91,9 +91,9 @@ module ArrayFu
|
|
91
91
|
include ArrayFu
|
92
92
|
attr_accessor :added
|
93
93
|
|
94
|
-
array :kids do
|
95
|
-
|
96
|
-
|
94
|
+
array :kids do
|
95
|
+
mutator :register_child
|
96
|
+
process_using :register_kids,:speak
|
97
97
|
end
|
98
98
|
|
99
99
|
def initialize
|
@@ -126,9 +126,9 @@ module ArrayFu
|
|
126
126
|
class Item
|
127
127
|
include ArrayFu
|
128
128
|
|
129
|
-
array :kids do
|
130
|
-
|
131
|
-
|
129
|
+
array :kids do
|
130
|
+
readable
|
131
|
+
mutator :register_child
|
132
132
|
end
|
133
133
|
|
134
134
|
def initialize
|
@@ -149,8 +149,8 @@ module ArrayFu
|
|
149
149
|
include ArrayFu
|
150
150
|
attr_accessor :added
|
151
151
|
|
152
|
-
array :kids do
|
153
|
-
|
152
|
+
array :kids do
|
153
|
+
mutator :register_child do|item|
|
154
154
|
@kids.push(item)
|
155
155
|
@added+=1
|
156
156
|
end
|
@@ -191,10 +191,10 @@ module ArrayFu
|
|
191
191
|
class OneClass
|
192
192
|
include ArrayFu
|
193
193
|
|
194
|
-
array :items do
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
array :items do
|
195
|
+
readable
|
196
|
+
mutator :add_item,:add_this,:add_that
|
197
|
+
new_item_must BeGreaterThanZero, RaiseCriteriaFailure
|
198
198
|
end
|
199
199
|
|
200
200
|
def initialize
|
@@ -227,10 +227,10 @@ module ArrayFu
|
|
227
227
|
class AnotherClass
|
228
228
|
include ArrayFu
|
229
229
|
|
230
|
-
array :items do
|
231
|
-
|
232
|
-
|
233
|
-
|
230
|
+
array :items do
|
231
|
+
readable
|
232
|
+
mutator :add_item,:add_this,:add_that
|
233
|
+
new_item_must BeGreaterThanZero, DisplayCriteriaFailure.instance
|
234
234
|
end
|
235
235
|
|
236
236
|
def initialize
|