valid-array 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 532ae5a1a7cebfcb358d915c3723b043d2cc583e
4
+ data.tar.gz: c5faa5e49edfeb7bbf35aa437c741cec4b12dfde
5
+ SHA512:
6
+ metadata.gz: 8b4c453c8148ac7f37d63edbe03d998bf1e56e8c4f5c98f5a3211fb0ba7546bb558490237d6c4433787f63f3b561f691aea082989aaeb8547d4cc9e1e8e53881
7
+ data.tar.gz: 6d292e56e43f7086364e05596a834a8a8d31f3f7babb5fa633ed14978ccca7d72847a59f050592be5b6b256e473f75dcb0dca8bd51a2bfa1330202af4aa84ae3
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 Ryan Biesemeyer
2
+ Copyright (c) 2013 Kevin Cox
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,77 @@
1
+ = valid-array
2
+
3
+ Gem provides enforced-properties to arrays.
4
+
5
+ Copyright (c) 2011 Ryan Biesemeyer
6
+ Copyright (c) 2013 Kevin Cox
7
+ See LICENSE.txt for details
8
+
9
+ Ryan Biesemeyer mailto:ruby-dev@yaauie.com
10
+ Ryan Biesemeyer mailto:kevincox@kevincox.ca
11
+
12
+ == Example
13
+
14
+ === ValidArray
15
+
16
+ Valid Array provides a hook to change and validate every element added to the
17
+ array.
18
+
19
+ require 'valid-array'
20
+ class StringArray < Array
21
+ extend ValidArray
22
+
23
+ def self.validate(element)
24
+ element.to_s # Make everything a String.
25
+ end
26
+ end
27
+
28
+ class EvenArray < Array
29
+ extend ValidArray
30
+
31
+ def self.validate(element)
32
+ if not element.is_a? Numeric
33
+ raise UnexpectedTypeException([Numeric], element.class)
34
+ end
35
+
36
+ if element % 2 == 1
37
+ # Assuming this exception is defined somewhere.
38
+ raise NotEvenException(element)
39
+ end
40
+ end
41
+ end
42
+
43
+ === TypedArray
44
+
45
+ TypedArray is fully compatible with https://github.com/yaauie/typed-array/.
46
+
47
+ === Create Standard Class
48
+
49
+ require 'typed-array'
50
+ class Things < Array
51
+ extend TypedArray
52
+ restrict_types Thing1,Thing2
53
+ end
54
+
55
+ === Generate Class using Factory
56
+
57
+ require 'typed-array'
58
+ things = TypedArray(Thing1,Thing2)
59
+
60
+ === Adding items to the Array
61
+
62
+ # All standard Array interfaces are implemented, including block-processing
63
+ # and variable-number of arguments. For methods that would usually return an
64
+ # Array, they instead return an instance of the current class (except to_a).
65
+ #
66
+ # The difference is that if the method would generate an Array including the
67
+ # wrong types, ValidArray::UnexpectedTypeException is raised and the call is
68
+ # aborted before modifying the enforced ValidArray instance.
69
+
70
+ require 'typed-array'
71
+ symbols = TypedArray(Symbol).new([:foo,:bar,:baz,:bingo])
72
+ begin
73
+ integers = TypedArray(Integer).new([1,3,7,2,:symbol])
74
+ rescue TypedArray::UnexpectedTypeException
75
+ puts "An error occured: #{$!}"
76
+ end
77
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "valid-array"
18
+ gem.homepage = "http://github.com/kevincox/valid-array"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Provides methods for creating type-enforced Arrays}
21
+ gem.description =<<-DESCRIPTION
22
+ All methods that alter the contents of an array that implements this Gem are first checked to
23
+ ensure that the added items are of the types allowed. All methods behave exactly as their Array
24
+ counterparts, including additional forms, block processing, etc.
25
+ DESCRIPTION
26
+ gem.email = "kevincox@kevincox.ca"
27
+ gem.authors = ["Kevin Cox", "Ryan Biesemeyer"]
28
+ gem.add_development_dependency("rdoc", "~> 3.9")
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "valid-array #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,61 @@
1
+ # :include: ../README.rdoc
2
+
3
+ require 'set'
4
+ require 'valid-array'
5
+
6
+ # Provides ValidArray functionality to a subclass of Array
7
+ # when extended in the class's definiton
8
+ module TypedArray
9
+ # when a class inherits from this one, make sure that it also inherits
10
+ # the types that are being enforced
11
+ def inherited(subclass)
12
+ self._subclasses << subclass
13
+ subclass.restricted_types *self.restricted_types
14
+ end
15
+
16
+ # A getter/setter for types to add. If no arguments are passed, it simply
17
+ # returns the current array of accepted types.
18
+ def restricted_types(*types)
19
+ @_restricted_types ||= []
20
+ types.each do |type|
21
+ raise UnexpectedTypeException.new([Class],type.class) unless type.is_a? Class
22
+ @_restricted_types << type unless @_restricted_types.include? type
23
+ _subclasses.each do |subclass|
24
+ subclass.restricted_types type
25
+ end
26
+ end
27
+ @_restricted_types
28
+ end; alias :restricted_type :restricted_types
29
+
30
+ UnexpectedTypeException = ValidArray::UnexpectedTypeException
31
+
32
+ # Default validator. Override this.
33
+ def validate(item)
34
+ if item.nil? or restricted_types.any? { |allowed| item.class <= allowed }
35
+ return item
36
+ else
37
+ raise TypedArray::UnexpectedTypeException.new(restricted_types, item.class)
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ # a store of subclasses
44
+ def _subclasses
45
+ @_subclasses ||= []
46
+ end
47
+
48
+ end
49
+
50
+ # Provide a factory method. Takes any number of types to accept as arguments
51
+ # and returns a class that behaves as a type-enforced array.
52
+ def TypedArray(*types_allowed)
53
+ klass = Class.new( Array )
54
+ klass.class_exec(types_allowed) do |types_allowed|
55
+ extend ValidArray
56
+ extend TypedArray
57
+
58
+ restricted_types *types_allowed
59
+ end
60
+ klass
61
+ end
@@ -0,0 +1,104 @@
1
+ # Provides the validation functions that get included into a ValidArray
2
+
3
+ # Namespace ValidArray
4
+ module ValidArray
5
+
6
+ # The functions that get included into ValidArray
7
+ module Functions
8
+ # Validates outcome. See Array#initialize
9
+ def initialize(*args, &block)
10
+ ary = Array.new *args, &block
11
+ self.replace ary
12
+ end
13
+
14
+ # Validates outcome. See Array#replace
15
+ def replace(other_ary)
16
+ _ensure_array_is_valid other_ary
17
+ super
18
+ end
19
+
20
+ # Validates outcome. See Array#&
21
+ def &(ary)
22
+ self.class.new super
23
+ end
24
+
25
+ # Validates outcome. See Array#*
26
+ def *(int)
27
+ self.class.new super
28
+ end
29
+
30
+ # Validates outcome. See Array#+
31
+ def +(ary)
32
+ self.class.new super
33
+ end
34
+
35
+ # Validates outcome. See Array#<<
36
+ def <<(item)
37
+ item = self.class.validate item
38
+ super
39
+ end
40
+
41
+ # Validates outcome. See Array#[]
42
+ def [](idx)
43
+ self.class.new super
44
+ end
45
+
46
+ # Validates outcome. See Array#slice
47
+ def slice(*args)
48
+ self.class.new super
49
+ end
50
+
51
+ # Validates outcome. See Array#[]=
52
+ def []=(idx, item)
53
+ item = self.class.validate item
54
+ super
55
+ end
56
+
57
+ # Validates outcome. See Array#concat
58
+ def concat(other_ary)
59
+ _ensure_array_is_valid other_ary
60
+ super
61
+ end
62
+
63
+ # Validates outcome. See Array#eql?
64
+ #def eql?(other_ary)
65
+ # _ensure_all_items_in_array_are_allowed other_ary
66
+ # super
67
+ #end
68
+
69
+ # Validates outcome. See Array#fill
70
+ def fill(*args, &block)
71
+ ary = self.to_a
72
+ ary.fill *args, &block
73
+ self.replace ary
74
+ end
75
+
76
+ # Validates outcome. See Array#push
77
+ def push(*items)
78
+ items = items.dup
79
+ _ensure_array_is_valid items
80
+ super
81
+ end
82
+
83
+ # Validates outcome. See Array#unshift
84
+ def unshift(*items)
85
+ items = items.dup
86
+ _ensure_array_is_valid items
87
+ super
88
+ end
89
+
90
+ # Validates outcome. See Array#map!
91
+ def map!(&block)
92
+ self.replace(self.map &block)
93
+ end
94
+
95
+ protected
96
+
97
+ # Ensure that all items in the passed Array are allowed
98
+ def _ensure_array_is_valid(ary)
99
+ ary.map! do |e|
100
+ self.class.validate(e)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,38 @@
1
+ # :include: ../README.rdoc
2
+
3
+ require 'valid-array/functions'
4
+
5
+ # Provides ValidArray functionality to a subclass of Array
6
+ # when extended in the class's definiton
7
+ module ValidArray
8
+ # Hook the extension process in order to include the necessary functions
9
+ # and do some basic sanity checks.
10
+ def self.extended(mod)
11
+ unless mod <= Array
12
+ raise UnexpectedTypeException.new([Array], mod.class)
13
+ end
14
+ mod.module_exec(self::Functions) do |functions_module|
15
+ include functions_module
16
+ end
17
+ end
18
+
19
+ # Default validator. Override this.
20
+ def validate(element)
21
+ raise NotImplementedError, "You must implement validate."
22
+ end
23
+
24
+ # The exception that is raised when an Unexpected Type is reached during validation
25
+ class UnexpectedTypeException < Exception
26
+ # Provide access to the types of objects expected and the class of the object received
27
+ attr_reader :expected, :received
28
+
29
+ def initialize(expected_one_of, received)
30
+ @expected = expected_one_of
31
+ @received = received
32
+ end
33
+
34
+ def to_s
35
+ %{Expected one of #{@expected.inspect} but received a(n) #{@received}}
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'typed-array'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,277 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ # We need to test in several different contexts, so provide the base info here.
4
+ inputs = {
5
+ [Symbol]=>{
6
+ :base => [:foo,:bar],
7
+ :match => [:baz,:bingo],
8
+ :fail => {
9
+ :one => [:zip,0],
10
+ :all => ['string',Class]
11
+ }
12
+ },
13
+ [Fixnum] => {
14
+ :base => [ 1,2,3 ],
15
+ :match => [ 17,18,19 ],
16
+ :fail => {
17
+ :one => [22,:symbol,43],
18
+ :all => ['string',:symbol]
19
+ }
20
+ },
21
+ [String,Symbol] => {
22
+ :base => ['Foo',:foo],
23
+ :match => [:bar,'Bar'],
24
+ :fail => {
25
+ :one => [:yippee,'a string',17],
26
+ :all => [12,Class,Array]
27
+ }
28
+ }
29
+ }
30
+
31
+ describe TypedArray do
32
+ describe '#new' do
33
+ inputs.each_pair do |accepted_types, config|
34
+ context "when only accepting <#{accepted_types.inspect}>" do
35
+ subject { TypedArray( *accepted_types ) }
36
+
37
+ context 'Form 1: typed_ary.new()' do
38
+ it "should have zero-length" do
39
+ subject.new().length.should == 0
40
+ end
41
+
42
+ it "should be empty" do
43
+ subject.new().to_a.should be_empty
44
+ end
45
+ end
46
+
47
+ context 'Form 1: typed_ary.new(size)' do
48
+ it "should have the proper length" do
49
+ subject.new(5).length.should == 5
50
+ end
51
+
52
+ it "should conatin all nil values" do
53
+ subject.new(5).to_a.should == [nil,nil,nil,nil,nil]
54
+ end
55
+ end
56
+
57
+ context 'Form 2: typed_ary.new(size,object)' do
58
+ it "should have the proper length" do
59
+ subject.new(3,config[:match].first).length.should == 3
60
+ end
61
+
62
+ it "should conatin the value specified" do
63
+ subject.new(3,config[:match].first).to_a.should == [config[:match].first]*3
64
+ end
65
+
66
+ it "should raise when obj is the wrong type" do
67
+ expect{ subject.new( 3, config[:fail][:all].first ) }.to raise_error TypedArray::UnexpectedTypeException
68
+ end
69
+ end
70
+
71
+ context 'Form 3: typed_ary.new( ary )' do
72
+ it "should accept when all items match" do
73
+ subject.new(config[:match]).to_a.should == config[:match]
74
+ end
75
+
76
+ it "should raise when one object is the wrong type" do
77
+ expect{ subject.new(config[:fail][:one])}.to raise_error TypedArray::UnexpectedTypeException
78
+ end
79
+
80
+ it "should raise when more than one object is the wrong type" do
81
+ expect{ subject.new(config[:fail][:all])}.to raise_error TypedArray::UnexpectedTypeException
82
+ end
83
+ end
84
+
85
+ context 'Form 4: typed_ary.new(size){|index|block}' do
86
+ it "should populate when block returns the right type" do
87
+ subject.new(config[:match].length){|i| config[:match][i]}.to_a.should == config[:match]
88
+ end
89
+
90
+ it "should raise when block returns wrong type once" do
91
+ expect{ subject.new(config[:fail][:one].length){|i| config[:fail][:one][i]} }.to raise_error TypedArray::UnexpectedTypeException
92
+ end
93
+
94
+ it "should raise when block returns wrong type more than once" do
95
+ expect{ subject.new(config[:fail][:all].length){|i| config[:fail][:all][i]} }.to raise_error TypedArray::UnexpectedTypeException
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ [:<<,:unshift,:push].each do |method|
103
+ context %Q{typed_ary#{('a'..'z').include?(method.to_s[0]) ? '.' : ' '}#{method.to_s} other_ary} do
104
+ inputs.each_pair do |accepted_types,config|
105
+ context "when only accepting <#{accepted_types.inspect}>" do
106
+ before :each do
107
+ @typed_ary = TypedArray( *accepted_types).new(config[:base])
108
+ @ary = config[:base].to_a
109
+ end
110
+
111
+ context "when the item being pushed matches (#{config[:match].first})" do
112
+ before :each do
113
+ @item = config[:match].first
114
+ end
115
+
116
+ it "should return as Array would return" do
117
+ @typed_ary.send(method,@item).to_a.should == @ary.send(method,@item)
118
+ end
119
+
120
+ it "should modify the TypedArray as Array would be modified" do
121
+ @typed_ary.send(method,@item)
122
+ @ary.send(method,@item)
123
+ @typed_ary.to_a.should == @ary
124
+ end
125
+ end
126
+
127
+ context "when the item being pushed does not match (#{config[:fail][:all].first})" do
128
+ before :each do
129
+ @item = config[:fail][:all].first
130
+ end
131
+
132
+ it "should raise an exception" do
133
+ expect{ @typed_ary.send(method,@item) }.to raise_error TypedArray::UnexpectedTypeException
134
+ end
135
+
136
+ it "should not modify typed_ary" do
137
+ begin
138
+ backup = @typed_ary.to_a
139
+ @typed_ary.send(method,@item)
140
+ rescue TypedArray::UnexpectedTypeException
141
+ ensure
142
+ @typed_ary.to_a.should == backup
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ [:[]=].each do |method|
152
+ context %Q{typed_ary[idx]= other_ary} do
153
+ inputs.each_pair do |accepted_types,config|
154
+ context "when only accepting <#{accepted_types.inspect}>" do
155
+ before :each do
156
+ @typed_ary = TypedArray( *accepted_types).new(config[:base])
157
+ @ary = config[:base].to_a
158
+ end
159
+
160
+ context "when the item being pushed matches (#{config[:match].first})" do
161
+ before :each do
162
+ @item = config[:match].first
163
+ end
164
+
165
+ it "should return as Array would return" do
166
+ @typed_ary.send(method,4,@item).should == @ary.send(method,4,@item)
167
+ end
168
+
169
+ it "should modify the TypedArray as Array would be modified" do
170
+ @typed_ary.send(method,4,@item)
171
+ @ary.send(method,4,@item)
172
+ @typed_ary.to_a.should == @ary
173
+ end
174
+ end
175
+
176
+ context "when the item being pushed does not match (#{config[:fail][:all].first})" do
177
+ before :each do
178
+ @item = config[:fail][:all].first
179
+ end
180
+
181
+ it "should raise an exception" do
182
+
183
+ expect{ @typed_ary.send(method,4,@item) }.to raise_error TypedArray::UnexpectedTypeException
184
+ end
185
+
186
+ it "should not modify typed_ary" do
187
+ begin
188
+ backup = @typed_ary.to_a
189
+ @typed_ary.send(method,4,@item)
190
+ rescue TypedArray::UnexpectedTypeException
191
+ ensure
192
+ @typed_ary.to_a.should == backup
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ [:+,:&,:concat,:replace].each do |method|
202
+ context %Q{typed_ary#{('a'..'z').include?(method.to_s[0]) ? '.' : ' '}#{method.to_s} other_ary} do
203
+ inputs.each_pair do |accepted_types,config|
204
+ context "when only accepting <#{accepted_types.inspect}>" do
205
+ before :each do
206
+ @typed_ary = TypedArray( *accepted_types).new(config[:base])
207
+ @ary = config[:base].to_a
208
+ end
209
+
210
+ context "when all items match (#{config[:match].inspect})" do
211
+ before :each do
212
+ @other_ary = config[:match].to_a
213
+ end
214
+
215
+ it "should return as Array would return" do
216
+ @typed_ary.send(method,@other_ary).to_a.should == @ary.send(method,@other_ary)
217
+ end
218
+
219
+ it "should modify the TypedArray as Array would be modified" do
220
+ @typed_ary.send(method,@other_ary)
221
+ @ary.send(method,@other_ary)
222
+ @typed_ary.to_a.should == @ary
223
+ end
224
+ end
225
+
226
+ config[:fail].each_key do |fail_type|
227
+ context "when #{fail_type} item fails to match (#{config[:fail][fail_type].inspect})" do
228
+ before :each do
229
+ @other_ary = config[:fail][fail_type].to_a
230
+ end
231
+ unless method == :& # `and` opperator cannot produce elements that are not in both arrays already; since one is assuredly filtered, we can skip this.
232
+ it "should raise an exception" do
233
+ expect{ @typed_ary.send(method,@other_ary) }.to raise_error TypedArray::UnexpectedTypeException
234
+ end
235
+ end
236
+
237
+ it "should not modify the TypedArray" do
238
+ begin
239
+ backup = @typed_ary.to_a
240
+ @typed_ary.send(method,@other_ary)
241
+ rescue TypedArray::UnexpectedTypeException
242
+ ensure
243
+ @typed_ary.to_a.should == backup
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ context 'when extending classes' do
254
+ before :each do
255
+ @base = TypedArray(Symbol)
256
+ @extension = Class.new( @base )
257
+ end
258
+
259
+ it 'should inherit default restrictions' do
260
+ @base.restricted_types.should == @extension.restricted_types
261
+ end
262
+
263
+ context 'when adding restricted_type to the parent' do
264
+ it 'should propogate to the child' do
265
+ @base.restricted_type Fixnum
266
+ @extension.restricted_types.should include(Fixnum)
267
+ end
268
+ end
269
+
270
+ context 'when adding restricted_type to the child' do
271
+ it 'should not propogate to the parent' do
272
+ @extension.restricted_type Fixnum
273
+ @base.restricted_types.should_not include(Fixnum)
274
+ end
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ValidArray do
4
+ context 'when custom validator is used' do
5
+ before :each do
6
+ class MyArray < Array
7
+ extend ValidArray
8
+
9
+ def self.validate(e)
10
+ e.to_s
11
+ end
12
+ end
13
+ @typed_ary = MyArray.new(5) {|i| i}
14
+ end
15
+
16
+ it 'should convert all values to strings' do
17
+ @typed_ary.each do |e|
18
+ e.should be_an_instance_of(String)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "valid-array"
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kevin Cox", "Ryan Biesemeyer"]
12
+ s.date = "2013-08-27"
13
+ s.description = " All methods that alter the contents of an array that implements this Gem are first checked to\n ensure that the added items are of the types allowed. All methods behave exactly as their Array\n counterparts, including additional forms, block processing, etc.\n"
14
+ s.email = "kevincox@kevincox.ca"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/typed-array.rb",
28
+ "lib/valid-array.rb",
29
+ "lib/valid-array/functions.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/typed-array_spec.rb",
32
+ "spec/valid-array_spec.rb",
33
+ "valid-array.gemspec"
34
+ ]
35
+ s.homepage = "http://github.com/kevincox/valid-array"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "2.0.3"
39
+ s.summary = "Provides methods for creating type-enforced Arrays"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<valid-array>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.6"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
52
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
53
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
55
+ s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
56
+ else
57
+ s.add_dependency(%q<valid-array>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.6"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
66
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
67
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<valid-array>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
73
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
74
+ s.add_dependency(%q<rspec>, ["~> 2.6"])
75
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
76
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
77
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
78
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
79
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
80
+ s.add_dependency(%q<rdoc>, ["~> 3.9"])
81
+ end
82
+ end
83
+
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: valid-array
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Cox
8
+ - Ryan Biesemeyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: valid-array
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: jeweler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rdoc
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.9'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.9'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '2.6'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '2.6'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdoc
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '3.9'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '3.9'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rdoc
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '3.9'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '3.9'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rdoc
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '3.9'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '3.9'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rdoc
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: '3.9'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '3.9'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rdoc
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '3.9'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: '3.9'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rdoc
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: '3.9'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ version: '3.9'
168
+ description: |2
169
+ All methods that alter the contents of an array that implements this Gem are first checked to
170
+ ensure that the added items are of the types allowed. All methods behave exactly as their Array
171
+ counterparts, including additional forms, block processing, etc.
172
+ email: kevincox@kevincox.ca
173
+ executables: []
174
+ extensions: []
175
+ extra_rdoc_files:
176
+ - LICENSE.txt
177
+ - README.rdoc
178
+ files:
179
+ - .document
180
+ - .rspec
181
+ - Gemfile
182
+ - LICENSE.txt
183
+ - README.rdoc
184
+ - Rakefile
185
+ - VERSION
186
+ - lib/typed-array.rb
187
+ - lib/valid-array.rb
188
+ - lib/valid-array/functions.rb
189
+ - spec/spec_helper.rb
190
+ - spec/typed-array_spec.rb
191
+ - spec/valid-array_spec.rb
192
+ - valid-array.gemspec
193
+ homepage: http://github.com/kevincox/valid-array
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.0.3
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Provides methods for creating type-enforced Arrays
217
+ test_files: []