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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a90d155b62053d740976ddc34cfbbcf0f5b30d04
4
- data.tar.gz: bfd56440c6bfc8e35b43b9614f13135c3c75effc
3
+ metadata.gz: 77b5a20091ff3fd52e2a31aa176d205ad90253a8
4
+ data.tar.gz: 38595e560fb27d9dabf1054d2611d01a04e6ed2d
5
5
  SHA512:
6
- metadata.gz: f5eb88f16b8067459c963d21389ff8904fa2b7a3d139ae0cdfabfd1278d0da9d52479df80ad37d4ca12e91a99d9b7c14b73fc7336d02184efb995b7aeb79d611
7
- data.tar.gz: 2ef91b2bca6aaaa484d7074db470c74462dc49d59a69dfad750218778e61d246908517858020b7d8468ddd347eda992f28881d03b215dc059f641eaa5c27e119
6
+ metadata.gz: 9e87aa4a17062bec29f00791c4f5a35727757dc9bee1639ed2c17a967a69dc9426f16c6480d73c9f599aee7d98be1ea12b94338e2d4fe949a067c559979599fe
7
+ data.tar.gz: 583d5bbc51a7d8e44a24472fd3093ef53e9ca0fe6ea587b5007310fc4d0b28bd87ce7caac3242e77c8522759c0669f907d317f62c9bedd1209029b642c326f9f
@@ -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
- array_definition = ArrayDefinition.new(name)
26
- yield array_definition if block_given?
27
- array_definitions << array_definition
28
- array_definition
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
@@ -1,3 +1,3 @@
1
1
  module ArrayFu
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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|a|
17
- a.readable
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|a|
33
- a.writable
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|a|
48
- a.read_and_write
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|a|
63
- a.mutator :add_item
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|a|
80
- a.mutator :add_item, :add_it, :push_it
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|a|
100
- a.mutator :add_item do|item|
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 |a|
119
- a.readable
118
+ array :secondary do
119
+ readable
120
120
  end
121
121
 
122
- array :names do|a|
123
- a.readable
124
- a.mutator :add_item do|item|
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|a|
166
- a.mutator :add_item,:add_it
167
- a.new_item_must NotBeJP, CriteriaViolation
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|a|
218
- a.mutator :add_item,:add_it
219
- a.addition_constraint NotBeJP
220
- a.addition_constraint NotBeNil, CriteriaViolation
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|a|
252
- a.mutator :add_item
253
- a.process_using :display_all,DisplayItem
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|a|
279
- a.mutator :add_item
280
- a.process_using :display_all, :process #the second symbol is the name of a method on an element in the array
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|a|
313
- a.mutator :add_item
314
- a.configure_using ArrayConfigs.add_another_mutator
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|a|
342
- a.mutator :add_item
343
- a.configure_using ArrayConfiguration
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|a|
373
- a.mutator :add_item
374
- a.configure_using ArrayConfiguration.configuration_block
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|a|
11
- a.readable
12
- a.mutator :register_child
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|a|
31
- a.readable
32
- a.mutator :register_child do|the_item|
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|a|
71
- a.mutator :register_child
72
- a.process_using :register_kids, OurVisitor.instance
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|a|
95
- a.mutator :register_child
96
- a.process_using :register_kids,:speak
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|a|
130
- a.readable
131
- a.mutator :register_child
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|a|
153
- a.mutator :register_child do|item|
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|a|
195
- a.readable
196
- a.mutator :add_item,:add_this,:add_that
197
- a.new_item_must BeGreaterThanZero, RaiseCriteriaFailure
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|a|
231
- a.readable
232
- a.mutator :add_item,:add_this,:add_that
233
- a.new_item_must BeGreaterThanZero, DisplayCriteriaFailure.instance
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arrayfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Develop With Passion®