arrayfu 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/arrayfu.gemspec +0 -0
  3. data/lib/arrayfu/array_definition.rb +84 -0
  4. data/lib/arrayfu/arrayfu.rb +31 -0
  5. data/lib/arrayfu/generate_mutators.rb +28 -0
  6. data/lib/arrayfu/{readable_step.rb → generate_readers.rb} +6 -4
  7. data/lib/arrayfu/generate_visitors.rb +18 -0
  8. data/lib/arrayfu/{writeable_step.rb → generate_writers.rb} +6 -4
  9. data/lib/arrayfu/initializer.rb +21 -0
  10. data/lib/arrayfu/item_constraint.rb +17 -0
  11. data/lib/arrayfu/module_registry.rb +9 -7
  12. data/lib/arrayfu/mutator_definition.rb +15 -0
  13. data/lib/arrayfu/version.rb +1 -1
  14. data/lib/arrayfu/visitor_definition.rb +19 -0
  15. data/lib/arrayfu.rb +10 -9
  16. data/spec/examples/{instance_usage.rb → usage.rb} +169 -72
  17. data/spec/specs/{dsl_spec.rb → array_definition_spec.rb} +20 -22
  18. data/spec/specs/dsl_usage_spec.rb +86 -52
  19. data/spec/specs/{mutator_step_spec.rb → generate_mutators_spec.rb} +5 -5
  20. data/spec/specs/{readable_step_spec.rb → generate_readers_spec.rb} +3 -3
  21. data/spec/specs/{visitor_detail_step_spec.rb → generate_visitors_spec.rb} +5 -5
  22. data/spec/specs/{writeable_step_spec.rb → generate_writers_step_spec.rb} +3 -3
  23. data/spec/specs/{object_extensions_spec.rb → initializer_spec.rb} +4 -1
  24. data/spec/specs/{add_criterion_spec.rb → item_constraint_spec.rb} +11 -11
  25. data/spec/specs/sample.rb +2 -0
  26. metadata +28 -29
  27. data/lib/arrayfu/add_criterion.rb +0 -16
  28. data/lib/arrayfu/dsl.rb +0 -43
  29. data/lib/arrayfu/mutator_detail.rb +0 -10
  30. data/lib/arrayfu/mutator_step.rb +0 -18
  31. data/lib/arrayfu/object_extensions.rb +0 -27
  32. data/lib/arrayfu/visitor_detail.rb +0 -10
  33. data/lib/arrayfu/visitor_detail_step.rb +0 -14
  34. data/spec/examples/class_usage.rb +0 -210
@@ -1,210 +0,0 @@
1
- require 'spec_helper'
2
-
3
- example "Basic" do
4
- class SomeClass
5
- array :names
6
- end
7
-
8
- SomeClass.names.should_not be_nil
9
- end
10
-
11
- example 'Allow the array to have a read accessor' do
12
- class SomeClass
13
- array :names do|a|
14
- a.readable
15
- end
16
- end
17
- SomeClass.names.should_not be_nil
18
- end
19
-
20
- example 'Allow the array to have a write accessor' do
21
- class SomeClass
22
- array :names do|a|
23
- a.writable
24
- end
25
- end
26
- SomeClass.names.should_not be_nil
27
- end
28
-
29
- example 'Allow the array to have a read and write accessor' do
30
- class SomeClass
31
- array :names do|a|
32
- a.read_and_write
33
- end
34
- end
35
- SomeClass.names.should_not be_nil
36
- end
37
-
38
- example 'Add a mutator method to the class that stores the array' do
39
- class SomeClass
40
- array :names do|a|
41
- a.mutator :add_item
42
- end
43
- end
44
-
45
- SomeClass.add_item("JP")
46
- SomeClass.names.count.should == 1
47
- end
48
-
49
- example 'Add multiple mutators to the class that stores the array' do
50
- class SomeClass
51
- array :names do|a|
52
- a.mutator :add_item,:add_it,:push_it
53
- end
54
- end
55
-
56
- SomeClass.add_item("JP")
57
- SomeClass.add_it("JP")
58
- SomeClass.push_it("JP")
59
- SomeClass.names.count.should == 3
60
- end
61
-
62
- example 'Add a mutator that ignores addition' do
63
- class SomeClass
64
- array :names do|a|
65
- a.mutator :add_item do|item|
66
- end
67
- end
68
- end
69
-
70
- SomeClass.add_item("JP")
71
- SomeClass.names.count.should == 0
72
- end
73
-
74
- example 'Add a mutator that does other custom logic as well as addition' do
75
- class SomeClass
76
- array :secondary
77
- array :names do|a|
78
- a.mutator :add_item do|item|
79
- @secondary.push item
80
- @names.push item
81
- end
82
- end
83
- end
84
-
85
- SomeClass.add_item("JP")
86
- SomeClass.names.count.should == 1
87
- SomeClass.secondary.count.should == 1
88
- end
89
-
90
- example 'Add a singular constraint and failure condition to each of the mutators' do
91
- class NotBeJP
92
- include Singleton
93
- def is_satisfied_by(item)
94
- return item != "JP"
95
- end
96
- def name
97
- return "The value should not be JP"
98
- end
99
- end
100
- class CriteriaViolation
101
- include Singleton
102
- def run(description,value)
103
-
104
- end
105
- end
106
-
107
- class SomeClass
108
- array :names do|a|
109
- a.mutator :add_item,:add_it
110
- a.new_item_must NotBeJP.instance,CriteriaViolation.instance
111
- end
112
- end
113
-
114
- SomeClass.add_item("JP")
115
- SomeClass.add_it("JP")
116
- SomeClass.names.count.should == 0
117
- end
118
-
119
- example 'Add multiple constraints and a failure condition to each of the mutators' do
120
- class NotBeJP
121
- include Singleton
122
- def is_satisfied_by(item)
123
- return item != "JP"
124
- end
125
- def name
126
- return "The value should not be JP"
127
- end
128
- end
129
- class NotBeNil
130
- include Singleton
131
- def is_satisfied_by(item)
132
- return item != nil
133
- end
134
- def name
135
- return "The value should not be nil"
136
- end
137
- end
138
- class CriteriaViolation
139
- include Singleton
140
- def run(description,value)
141
-
142
- end
143
- end
144
-
145
- class SomeClass
146
- array :names do|a|
147
- a.mutator :add_item,:add_it
148
- a.new_item_must NotBeJP.instance,CriteriaViolation.instance
149
- a.new_item_must NotBeNil.instance,CriteriaViolation.instance
150
- end
151
- end
152
-
153
- SomeClass.add_item("JP")
154
- SomeClass.add_it("JP")
155
- SomeClass.add_item(nil)
156
- SomeClass.names.count.should == 0
157
- end
158
-
159
- example 'Add an explicit processing visitor to the array' do
160
- class DisplayItem
161
- @@number_of_items_displayed = 0
162
- class << self
163
- def run_using(item)
164
- @@number_of_items_displayed += 1
165
- end
166
- def item_count
167
- return @@number_of_items_displayed
168
- end
169
- end
170
- end
171
-
172
- class SomeClass
173
- array :names do|a|
174
- a.mutator :add_item
175
- a.process_using :display_all,DisplayItem
176
- end
177
- end
178
-
179
- (1..10).each{|item| SomeClass.add_item(item)}
180
- SomeClass.display_all
181
- DisplayItem.item_count.should == 10
182
- end
183
-
184
- example 'Add an method based processing visitor to the array based on a method that exists on the items in the array' do
185
- class Item
186
- def process
187
- SomeClass.increment
188
- end
189
- end
190
-
191
- class SomeClass
192
- @@items_visited = 0
193
- array :names do|a|
194
- a.mutator :add_item
195
- a.process_using :display_all,:process #the second symbol is the name of a method on an element in the array
196
- end
197
-
198
- #the process method of the Item class invokes this method (a little bit roundabout, but it hopefully demonstrates the capability
199
- def self.increment
200
- @@items_visited += 1
201
- end
202
- def self.number_of_items_visited
203
- @@items_visited
204
- end
205
- end
206
-
207
- (1..10).each{|item| SomeClass.add_item(Item.new)}
208
- SomeClass.display_all
209
- SomeClass.number_of_items_visited.should == 10
210
- end