arrayfu 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArrayFu
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,210 @@
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
@@ -0,0 +1,243 @@
1
+ require 'spec_helper'
2
+
3
+ example "Basic" do
4
+ class SomeClass
5
+ def initialize
6
+ array :names
7
+ end
8
+ end
9
+
10
+ SomeClass.new.names.should_not be_nil
11
+ end
12
+
13
+ example 'Allow the array to have a read accessor' do
14
+ class SomeClass
15
+ def initialize
16
+ array :names do|a|
17
+ a.readable
18
+ end
19
+ end
20
+ end
21
+ SomeClass.new.names.should_not be_nil
22
+ end
23
+
24
+ example 'Allow the array to have a write accessor' do
25
+ class SomeClass
26
+ def initialize
27
+ array :names do|a|
28
+ a.writable
29
+ end
30
+ end
31
+ end
32
+ SomeClass.new.names.should_not be_nil
33
+ end
34
+
35
+ example 'Allow the array to have a read and write accessor' do
36
+ class SomeClass
37
+ def initialize
38
+ array :names do|a|
39
+ a.read_and_write
40
+ end
41
+ end
42
+ end
43
+ SomeClass.new.names.should_not be_nil
44
+ end
45
+
46
+ example 'Add a mutator method to the class that stores the array' do
47
+ class SomeClass
48
+ def initialize
49
+ array :names do|a|
50
+ a.mutator :add_item
51
+ end
52
+ end
53
+ end
54
+
55
+ items = SomeClass.new
56
+ items.add_item("JP")
57
+ items.names.count.should == 1
58
+ end
59
+
60
+ example 'Add multiple mutators to the class that stores the array' do
61
+ class SomeClass
62
+ def initialize
63
+ array :names do|a|
64
+ a.mutator :add_item,:add_it,:push_it
65
+ end
66
+ end
67
+ end
68
+
69
+ items = SomeClass.new
70
+ items.add_item("JP")
71
+ items.add_it("JP")
72
+ items.push_it("JP")
73
+ items.names.count.should == 3
74
+ end
75
+
76
+ example 'Add a mutator that ignores addition' do
77
+ class SomeClass
78
+ def initialize
79
+ array :names do|a|
80
+ a.mutator :add_item do|item|
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ items = SomeClass.new
87
+ items.add_item("JP")
88
+ items.names.count.should == 0
89
+ end
90
+
91
+ example 'Add a mutator that does other custom logic as well as addition' do
92
+ class SomeClass
93
+ def initialize
94
+ array :secondary
95
+ array :names do|a|
96
+ a.mutator :add_item do|item|
97
+ @secondary.push item
98
+ @names.push item
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ items = SomeClass.new
105
+ items.add_item("JP")
106
+ items.names.count.should == 1
107
+ items.secondary.count.should == 1
108
+ end
109
+
110
+ example 'Add a singular constraint and failure condition to each of the mutators' do
111
+ class NotBeJP
112
+ include Singleton
113
+ def is_satisfied_by(item)
114
+ return item != "JP"
115
+ end
116
+ def name
117
+ return "The value should not be JP"
118
+ end
119
+ end
120
+ class CriteriaViolation
121
+ include Singleton
122
+ def run(description,value)
123
+
124
+ end
125
+ end
126
+
127
+ class SomeClass
128
+ def initialize
129
+ array :names do|a|
130
+ a.mutator :add_item,:add_it
131
+ a.new_item_must NotBeJP.instance,CriteriaViolation.instance
132
+ end
133
+ end
134
+ end
135
+
136
+ items = SomeClass.new
137
+ items.add_item("JP")
138
+ items.add_it("JP")
139
+ items.names.count.should == 0
140
+ end
141
+
142
+ example 'Add multiple constraints and a failure condition to each of the mutators' do
143
+ class NotBeJP
144
+ include Singleton
145
+ def is_satisfied_by(item)
146
+ return item != "JP"
147
+ end
148
+ def name
149
+ return "The value should not be JP"
150
+ end
151
+ end
152
+ class NotBeNil
153
+ include Singleton
154
+ def is_satisfied_by(item)
155
+ return item != nil
156
+ end
157
+ def name
158
+ return "The value should not be nil"
159
+ end
160
+ end
161
+ class CriteriaViolation
162
+ include Singleton
163
+ def run(description,value)
164
+
165
+ end
166
+ end
167
+
168
+ class SomeClass
169
+ def initialize
170
+ array :names do|a|
171
+ a.mutator :add_item,:add_it
172
+ a.new_item_must NotBeJP.instance,CriteriaViolation.instance
173
+ a.new_item_must NotBeNil.instance,CriteriaViolation.instance
174
+ end
175
+ end
176
+ end
177
+
178
+ items = SomeClass.new
179
+ items.add_item("JP")
180
+ items.add_it("JP")
181
+ items.add_item(nil)
182
+ items.names.count.should == 0
183
+ end
184
+
185
+ example 'Add an explicit processing visitor to the array' do
186
+ class DisplayItem
187
+ @@number_of_items_displayed = 0
188
+ class << self
189
+ def run_using(item)
190
+ @@number_of_items_displayed += 1
191
+ end
192
+ def item_count
193
+ return @@number_of_items_displayed
194
+ end
195
+ end
196
+ end
197
+
198
+ class SomeClass
199
+ def initialize
200
+ array :names do|a|
201
+ a.mutator :add_item
202
+ a.process_using :display_all,DisplayItem
203
+ end
204
+ end
205
+ end
206
+
207
+ items = SomeClass.new
208
+ (1..10).each{|item| items.add_item(item)}
209
+ items.display_all
210
+ DisplayItem.item_count.should == 10
211
+ end
212
+
213
+ example 'Add an method based processing visitor to the array based on a method that exists on the items in the array' do
214
+ class Item
215
+ def process
216
+ SomeClass.increment
217
+ end
218
+ end
219
+
220
+ class SomeClass
221
+ @@items_visited = 0
222
+
223
+ def initialize
224
+ array :names do|a|
225
+ a.mutator :add_item
226
+ a.process_using :display_all,:process #the second symbol is the name of a method on an element in the array
227
+ end
228
+ end
229
+
230
+ #the process method of the Item class invokes this method (a little bit roundabout, but it hopefully demonstrates the capability
231
+ def self.increment
232
+ @@items_visited += 1
233
+ end
234
+ def self.number_of_items_visited
235
+ @@items_visited
236
+ end
237
+ end
238
+
239
+ items = SomeClass.new
240
+ (1..10).each{|item| items.add_item(Item.new)}
241
+ items.display_all
242
+ SomeClass.number_of_items_visited.should == 10
243
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'fileutils'
2
2
  require 'fakes-rspec'
3
3
  require 'singleton'
4
+ require 'rspec'
5
+
6
+ include RSpec::Matchers
4
7
 
5
8
  Dir.chdir(File.join(File.dirname(__FILE__),"..,lib".split(','))) do
6
9
  require 'arrayfu.rb'
@@ -15,3 +18,10 @@ def catch_exception
15
18
  exception
16
19
  end
17
20
 
21
+ def example name,&block
22
+ describe "Example:" do
23
+ it name do
24
+ yield
25
+ end
26
+ end
27
+ end
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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70297638968580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *70297638968580
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: guard
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70297638968140 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70297638968140
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: guard-rspec
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70297638967680 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *70297638967680
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: fakes-rspec
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70297638967240 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,12 +54,7 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70297638967240
78
58
  description: Simple DSL For Declaritive Arrays
79
59
  email:
80
60
  - open_source@developwithpassion.com
@@ -102,6 +82,8 @@ files:
102
82
  - lib/core/visitor_detail.rb
103
83
  - lib/core/visitor_detail_step.rb
104
84
  - lib/core/writeable_step.rb
85
+ - spec/examples/class_usage.rb
86
+ - spec/examples/instance_usage.rb
105
87
  - spec/spec_helper.rb
106
88
  - spec/specs/add_criterion_spec.rb
107
89
  - spec/specs/dsl_spec.rb
@@ -131,11 +113,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
113
  version: '0'
132
114
  requirements: []
133
115
  rubyforge_project: arrayfu
134
- rubygems_version: 1.8.21
116
+ rubygems_version: 1.8.15
135
117
  signing_key:
136
118
  specification_version: 3
137
119
  summary: Simple DSL For Declaritive Arrays
138
120
  test_files:
121
+ - spec/examples/class_usage.rb
122
+ - spec/examples/instance_usage.rb
139
123
  - spec/spec_helper.rb
140
124
  - spec/specs/add_criterion_spec.rb
141
125
  - spec/specs/dsl_spec.rb