validation 0.0.7.1 → 0.1.0

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: 72e13757f98dda6f8a50388fb7f2ff0f46f440cb
4
- data.tar.gz: 6632a89edc42aa3c245e2707b8ca0999bb349502
3
+ metadata.gz: a72a75a91be19767fda6f4bff040894b69667031
4
+ data.tar.gz: '000188dc7810938cd87ce143879b109d8927f544'
5
5
  SHA512:
6
- metadata.gz: e44bca8e583a685ecb717021eab139a90ff064383d7f39d05f53c22f145a6f3083f887d1b2191c51a487471ee38efc704f4251dfc2a7be5ba2a4f8ec6cbc01cd
7
- data.tar.gz: 19982b68cbf76137693e0ccd7a5b9fe6020530d087a6aeacc929acb162a98c502df54fcf1b66e1a8ab36c0ab5047df7f40c7043df30a744aebf96e72aaf837e5
6
+ metadata.gz: 4346f8c1265606e45b63a9a45685190dcb9ed4ed0168537581791f6f2ee2b21c368e91b2b0923b89c820a0d5b3479af17cd0258c13d582756e07aca5e2bdbe81
7
+ data.tar.gz: 73ebc21773887154497a4babdf3ca3230d8e50a1c533f06ce7943564bc59717638d332f9d2c97af94c685710c0815b50617b43bc2cd3512acf00ea153e4cb729
@@ -1,19 +1,17 @@
1
1
  language: ruby
2
-
2
+ sudo: false
3
+ branches:
4
+ only:
5
+ - master
3
6
  rvm:
7
+ - 2.4.2
8
+ - 2.3.5
9
+ - 2.2.7
4
10
  - ruby-head
5
- - 2.0.0
6
- - 1.9.3
7
- - rbx
11
+ - rbx-3
8
12
  - jruby-head
9
- - jruby-19mode
10
-
11
13
  matrix:
12
14
  allow_failures:
13
15
  - rvm: ruby-head
14
- - rvm: rbx
16
+ - rvm: rbx-3
15
17
  - rvm: jruby-head
16
- - rvm: jruby-19mode
17
-
18
- before_install:
19
- - gem install bundler
data/README.md CHANGED
@@ -7,14 +7,11 @@ validation
7
7
  Description
8
8
  -----------
9
9
 
10
- I think validations are not only for Web Apps :)
10
+ Validations with Ruby objects.
11
11
 
12
12
  Features
13
13
  --------
14
14
 
15
- * Provide a way of defining validations anywhere
16
- * Easy and Flexible validation combinators
17
- * And adjusters
18
15
  * Pure Ruby :)
19
16
 
20
17
  Usage
@@ -31,7 +28,7 @@ require 'validation'
31
28
 
32
29
  class Person
33
30
  include Validation
34
-
31
+
35
32
  attr_validator :name, String
36
33
  attr_validator :id, OR(nil, AND(Integer, 1..100))
37
34
  end
@@ -53,7 +50,7 @@ person.id = 1 #=> Pass
53
50
  Requirements
54
51
  -------------
55
52
 
56
- * [Ruby 1.9.3 or later](http://travis-ci.org/#!/kachick/validation)
53
+ * [Tested on Ruby 2.2 or later (Also 2.5 :)](http://travis-ci.org/#!/kachick/validation)
57
54
 
58
55
  Install
59
56
  -------
@@ -77,4 +74,4 @@ License
77
74
 
78
75
  The MIT X11 License
79
76
  Copyright (c) 2011-2012 Kenichi Kamiya
80
- See MIT-LICENSE for further details.
77
+ See MIT-LICENSE for further details.
@@ -6,7 +6,7 @@ require_relative '../lib/validation'
6
6
 
7
7
  class Person
8
8
  include Validation
9
-
9
+
10
10
  attr_validator :name, String
11
11
  attr_validator :id, OR(nil, AND(Integer, 1..100))
12
12
  end
@@ -1,13 +1,11 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
4
  module Adjustment
6
-
7
5
  module_function
8
-
6
+
9
7
  # @group Support Building Adjusters
10
-
8
+
11
9
  # true if argument is sufficient for adjuster.
12
10
  # A adjuster have to be arity equal 1.
13
11
  def adjustable?(object)
@@ -22,7 +20,7 @@ module Validation
22
20
  end
23
21
  end
24
22
  end
25
-
23
+
26
24
  # Adjuster Builders
27
25
  # Apply adjuster when passed condition.
28
26
  # @param condition [Proc, Method, #===]
@@ -30,16 +28,16 @@ module Validation
30
28
  # @return [lambda]
31
29
  def WHEN(condition, adjuster)
32
30
  unless Validation.conditionable? condition
33
- raise TypeError, 'wrong object for condition'
31
+ raise TypeError, 'wrong object for condition'
34
32
  end
35
33
 
36
34
  unless Validation.adjustable? adjuster
37
- raise TypeError, 'wrong object for adjuster'
35
+ raise TypeError, 'wrong object for adjuster'
38
36
  end
39
-
37
+
40
38
  ->v{_valid?(condition, v) ? adjuster.call(v) : v}
41
39
  end
42
-
40
+
43
41
  # Sequencial apply all adjusters.
44
42
  # @param adjuster1 [Proc, #to_proc]
45
43
  # @param adjuster2 [Proc, #to_proc]
@@ -64,7 +62,7 @@ module Validation
64
62
  if !::Integer.equal?(parser) and !parser.respond_to?(:parse)
65
63
  raise TypeError, 'wrong object for parser'
66
64
  end
67
-
65
+
68
66
  ->v{
69
67
  if ::Integer.equal? parser
70
68
  ::Kernel.Integer v
@@ -76,7 +74,7 @@ module Validation
76
74
  when ->_{v.respond_to? :to_str}
77
75
  v.to_str
78
76
  when ->_{v.respond_to? :read}
79
- v.read
77
+ v.read
80
78
  else
81
79
  raise TypeError, 'wrong object for parsing source'
82
80
  end
@@ -84,9 +82,7 @@ module Validation
84
82
  end
85
83
  }
86
84
  end
87
-
88
- # @endgroup
89
85
 
86
+ # @endgroup
90
87
  end
91
-
92
88
  end
@@ -1,13 +1,10 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
4
  module Condition
6
-
7
5
  module_function
8
-
9
6
  # @group Support Building Conditions
10
-
7
+
11
8
  # true if object is sufficient for condition.
12
9
  # @param [Object] object
13
10
  def conditionable?(object)
@@ -18,24 +15,24 @@ module Validation
18
15
  object.respond_to? :===
19
16
  end
20
17
  end
21
-
18
+
22
19
  # Condition Builders
23
20
  # A innner method for some condition builders.
24
21
  # For build conditions AND, NAND, OR, NOR, XOR, XNOR.
25
22
  # @param delegated [Symbol]
26
- # @return [lambda]
23
+ # @return [lambda]
27
24
  def _logical_operator(delegated, *conditions)
28
25
  unless conditions.all?{|c|conditionable? c}
29
26
  raise TypeError, 'wrong object for condition'
30
27
  end
31
-
28
+
32
29
  ->v{
33
30
  conditions.__send__(delegated) {|condition|
34
31
  _valid? condition, v
35
32
  }
36
33
  }
37
34
  end
38
-
35
+
39
36
  class << self
40
37
  private :_logical_operator
41
38
  end
@@ -49,12 +46,12 @@ module Validation
49
46
  def AND(cond1, cond2, *conds)
50
47
  _logical_operator :all?, cond1, cond2, *conds
51
48
  end
52
-
49
+
53
50
  # A condition builder.
54
51
  # @param cond1 [Proc, Method, #===]
55
52
  # @param cond2 [Proc, Method, #===]
56
53
  # @param conds [Proc, Method, #===]
57
- # @return [lambda]
54
+ # @return [lambda]
58
55
  def NAND(cond1, cond2, *conds)
59
56
  NOT AND(cond1, cond2, *conds)
60
57
  end
@@ -86,12 +83,12 @@ module Validation
86
83
  def XOR(cond1, cond2, *conds)
87
84
  _logical_operator :one?, cond1, cond2, *conds
88
85
  end
89
-
86
+
90
87
  # A condition builder.
91
88
  # @param cond1 [Proc, Method, #===]
92
89
  # @param cond2 [Proc, Method, #===]
93
90
  # @param conds [Proc, Method, #===]
94
- # @return [lambda]
91
+ # @return [lambda]
95
92
  def XNOR(cond1, cond2, *conds)
96
93
  NOT XOR(cond1, cond2, *conds)
97
94
  end
@@ -103,7 +100,7 @@ module Validation
103
100
  unless conditionable? condition
104
101
  raise TypeError, 'wrong object for condition'
105
102
  end
106
-
103
+
107
104
  ->v{! _valid?(condition, v)}
108
105
  end
109
106
 
@@ -137,7 +134,7 @@ module Validation
137
134
  }
138
135
  raise TypeError, 'only Symbol or String for message'
139
136
  end
140
-
137
+
141
138
  ->v{
142
139
  messages.all?{|message|v.respond_to? message}
143
140
  }
@@ -148,13 +145,13 @@ module Validation
148
145
  # @param conditions [Proc, Method, #===]
149
146
  # @return [lambda]
150
147
  # this lambda return true
151
- # if face no exception when a argment checking under all conditions
148
+ # if face no exception when a argment checking under all conditions
152
149
  def QUIET(condition, *conditions)
153
150
  conditions = [condition, *conditions]
154
151
  unless conditions.all?{|c|conditionable? c}
155
152
  raise TypeError, 'wrong object for condition'
156
153
  end
157
-
154
+
158
155
  ->v{
159
156
  conditions.all?{|cond|
160
157
  begin
@@ -167,7 +164,7 @@ module Validation
167
164
  }
168
165
  }
169
166
  end
170
-
167
+
171
168
  # A condition builder.
172
169
  # @param exception [Exception]
173
170
  # @param exceptions [Exception]
@@ -178,7 +175,7 @@ module Validation
178
175
  exceptions = [exception, *exceptions]
179
176
  raise ArgumentError unless conditionable? condition
180
177
  raise TypeError unless exceptions.all?{|e|e.ancestors.include? Exception}
181
-
178
+
182
179
  ->v{
183
180
  begin
184
181
  _valid? condition, v
@@ -200,7 +197,7 @@ module Validation
200
197
  def CATCH(exception, &condition)
201
198
  raise ArgumentError unless conditionable? condition
202
199
  raise TypeError, 'not error object' unless exception.ancestors.include? Exception
203
-
200
+
204
201
  ->v{
205
202
  begin
206
203
  _valid? condition, v
@@ -223,7 +220,7 @@ module Validation
223
220
  unless conditions.all?{|c|conditionable? c}
224
221
  raise TypeError, 'wrong object for condition'
225
222
  end
226
-
223
+
227
224
  ->list{
228
225
  enum = (
229
226
  (list.respond_to?(:each_value) && list.each_value) or
@@ -231,7 +228,7 @@ module Validation
231
228
  (list.respond_to?(:each) && list.each) or
232
229
  return false
233
230
  )
234
-
231
+
235
232
  conditions.all?{|cond|
236
233
  enum.all?{|v|
237
234
  _valid? cond, v
@@ -242,7 +239,7 @@ module Validation
242
239
 
243
240
  alias_method :GENERICS, :ALL
244
241
  module_function :GENERICS
245
-
242
+
246
243
  # A condition builder.
247
244
  # @param list [#all?]
248
245
  # @param lists [#all?]
@@ -254,31 +251,31 @@ module Validation
254
251
  unless lists.all?{|l|l.respond_to? :all?}
255
252
  raise TypeError, 'list must respond #all?'
256
253
  end
257
-
254
+
258
255
  ->v{
259
256
  lists.all?{|l|l.include? v}
260
257
  }
261
258
  end
262
259
 
263
260
  # @endgroup
264
-
261
+
265
262
  # @group Useful Conditions
266
263
  ANYTHING = BasicObject # BasicObject.=== always passing
267
264
  BOOLEAN = ->v{v.equal?(true) || v.equal?(false)}
268
265
  STRINGABLE = OR(String, Symbol, CAN(:to_str), CAN(:to_sym))
269
-
266
+
270
267
  module_function
271
268
 
272
269
  def ANYTHING?
273
270
  ANYTHING
274
271
  end
275
-
272
+
276
273
  # A getter for a useful condition.
277
274
  # @return [BOOLEAN] "true or false"
278
275
  def BOOLEAN?
279
276
  BOOLEAN
280
277
  end
281
-
278
+
282
279
  alias_method :BOOL?, :BOOLEAN?
283
280
  module_function :BOOL?
284
281
 
@@ -287,9 +284,7 @@ module Validation
287
284
  def STRINGABLE?
288
285
  STRINGABLE
289
286
  end
290
-
291
- # @endgroup
292
287
 
288
+ # @endgroup
293
289
  end
294
-
295
290
  end
@@ -1,11 +1,9 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
4
  class InvalidError < TypeError; end
6
5
  class InvalidReadingError < InvalidError; end
7
6
  class InvalidWritingError < InvalidError; end
8
7
  class InvalidAdjustingError < InvalidError; end
9
8
  UnmanagebleError = InvalidAdjustingError
10
-
11
9
  end
@@ -1,7 +1,6 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
4
  module_function
6
5
 
7
6
  def conditionable?(object)
@@ -11,5 +10,4 @@ module Validation
11
10
  def adjustable?(object)
12
11
  Adjustment.__send__ __callee__, object
13
12
  end
14
-
15
13
  end
@@ -1,22 +1,17 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
4
  class << self
6
-
5
+
7
6
  private
8
-
7
+
9
8
  def included(mod)
10
9
  mod.module_eval do
11
-
12
10
  extend Condition
13
11
  extend Adjustment
14
12
  extend Validatable::ClassMethods
15
13
  include Validatable
16
-
17
14
  end
18
15
  end
19
-
20
16
  end
21
-
22
17
  end
@@ -3,7 +3,6 @@
3
3
  require_relative 'validatable/classmethods'
4
4
 
5
5
  module Validation
6
-
7
6
  # A way of defining accessor with flexible validations.
8
7
  # @example define accessor with validations
9
8
  # class Person
@@ -12,7 +11,6 @@ module Validation
12
11
  # attr_validator :birthday, Time
13
12
  # end
14
13
  module Validatable
15
-
16
14
  private
17
15
 
18
16
  # @param [Proc, Method, #===] condition
@@ -27,7 +25,5 @@ module Validation
27
25
  condition === value
28
26
  end ? true : false
29
27
  end
30
-
31
28
  end
32
-
33
29
  end
@@ -1,9 +1,7 @@
1
1
  # coding: us-ascii
2
2
 
3
- module Validation; module Validatable
4
-
3
+ module Validation; module Validatable
5
4
  module ClassMethods
6
-
7
5
  ACCESSOR_OPTIONS = [:reader_validation, :writer_validation].freeze
8
6
 
9
7
  # @param name [Symbol, String]
@@ -11,7 +9,7 @@ module Validation; module Validatable
11
9
  def attr_reader_with_validation(name, condition=ANYTHING)
12
10
  define_method name do
13
11
  value = instance_variable_get :"@#{name}"
14
-
12
+
15
13
  unless _valid? condition, value
16
14
  raise InvalidReadingError,
17
15
  "#{value.inspect} is deficient for #{name} in #{self.class}"
@@ -19,17 +17,17 @@ module Validation; module Validatable
19
17
 
20
18
  value
21
19
  end
22
-
20
+
23
21
  nil
24
22
  end
25
23
 
26
24
  # @param name [Symbol, String]
27
- # @param condition [Proc, Method, #===]
28
- def attr_writer_with_validation(name, condition=ANYTHING, &adjuster)
25
+ # @param condition [Proc, Method, #===]
26
+ def attr_writer_with_validation(name, condition=ANYTHING, &adjuster)
29
27
  if block_given?
30
28
  adjustment = true
31
29
  end
32
-
30
+
33
31
  define_method :"#{name}=" do |value|
34
32
  raise "can't modify frozen #{self.class}" if frozen?
35
33
 
@@ -40,7 +38,7 @@ module Validation; module Validatable
40
38
  raise InvalidAdjustingError, $!
41
39
  end
42
40
  end
43
-
41
+
44
42
  if _valid? condition, value
45
43
  instance_variable_set :"@#{name}", value
46
44
  else
@@ -48,7 +46,7 @@ module Validation; module Validatable
48
46
  "#{value.inspect} is deficient for #{name} in #{self.class}"
49
47
  end
50
48
  end
51
-
49
+
52
50
  nil
53
51
  end
54
52
 
@@ -61,13 +59,13 @@ module Validation; module Validatable
61
59
  unless (options.keys - ACCESSOR_OPTIONS).empty?
62
60
  raise ArgumentError, 'invalid option parameter is'
63
61
  end
64
-
62
+
65
63
  if options[:reader_validation]
66
64
  attr_reader_with_validation name, condition
67
65
  else
68
66
  attr_reader name
69
67
  end
70
-
68
+
71
69
  if options[:writer_validation]
72
70
  attr_writer_with_validation name, condition, &adjuster
73
71
  else
@@ -82,7 +80,5 @@ module Validation; module Validatable
82
80
  :attr_accessor_with_validation,
83
81
  :attr_validator
84
82
  )
85
-
86
- end
87
-
83
+ end
88
84
  end; end
@@ -1,7 +1,5 @@
1
1
  # coding: us-ascii
2
2
 
3
3
  module Validation
4
-
5
- VERSION = '0.0.7.1'.freeze
6
-
4
+ VERSION = '0.1.0'.freeze
7
5
  end
@@ -5,27 +5,27 @@ require_relative 'test_helper'
5
5
  class TestValidationFunctionalCondition < Test::Unit::TestCase
6
6
  class Sthlambda
7
7
  include Validation
8
-
8
+
9
9
  def lanks
10
10
  1..20
11
11
  end
12
-
12
+
13
13
  attr_validator :lank, ->lank{lanks.include? lank}
14
14
  end
15
-
15
+
16
16
  def test_lambda
17
17
  sth = Sthlambda.new
18
18
  sth.lank = 2
19
19
  assert_equal 2, sth.lank
20
-
20
+
21
21
  assert_raises Validation::InvalidWritingError do
22
22
  sth.lank = 31
23
23
  end
24
24
  end
25
-
25
+
26
26
  class SthProc
27
27
  include Validation
28
-
28
+
29
29
  attr_validator :lank, Proc.new{|n|(3..9) === n}
30
30
  end
31
31
 
@@ -33,23 +33,23 @@ class TestValidationFunctionalCondition < Test::Unit::TestCase
33
33
  sth = SthProc.new
34
34
  sth.lank = 8
35
35
  assert_equal 8, sth.lank
36
-
36
+
37
37
  assert_raises Validation::InvalidWritingError do
38
38
  sth.lank = 2
39
39
  end
40
40
  end
41
-
41
+
42
42
  class SthMethod
43
43
  include Validation
44
-
44
+
45
45
  attr_validator :lank, 7.method(:<)
46
46
  end
47
-
47
+
48
48
  def test_Method
49
49
  sth = SthMethod.new
50
50
  sth.lank = 8
51
51
  assert_equal 8, sth.lank
52
-
52
+
53
53
  assert_raises Validation::InvalidWritingError do
54
54
  sth.lank = 6
55
55
  end
@@ -86,18 +86,18 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
86
86
  assert(Validation::Condition::ANYTHING === BasicObject.new)
87
87
 
88
88
  sth = Sth.new
89
-
89
+
90
90
  obj = BasicObject.new
91
-
91
+
92
92
  sth.always_passing = obj
93
93
  assert_same obj, sth.always_passing
94
94
  end
95
95
 
96
96
  def test_not
97
97
  sth = Sth.new
98
-
98
+
99
99
  obj = Object.new
100
-
100
+
101
101
  sth.not_integer = obj
102
102
  assert_same obj, sth.not_integer
103
103
 
@@ -108,9 +108,9 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
108
108
 
109
109
  def test_quiet
110
110
  sth = Sth.new
111
-
111
+
112
112
  obj = Object.new
113
-
113
+
114
114
  sth.no_exception = obj
115
115
  assert_same obj, sth.no_exception
116
116
  sth.no_exception = false
@@ -126,9 +126,9 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
126
126
 
127
127
  def test_catch
128
128
  sth = Sth.new
129
-
129
+
130
130
  obj = Object.new
131
-
131
+
132
132
  sth.catch_error = obj
133
133
  assert_same obj, sth.catch_error
134
134
  sth.catch_error = false
@@ -141,15 +141,15 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
141
141
  assert_raises Validation::InvalidWritingError do
142
142
  sth.catch_error = obj
143
143
  end
144
-
144
+
145
145
  obj.singleton_class.class_eval do
146
146
  remove_method :no_name!
147
-
147
+
148
148
  def no_name!
149
149
  raise NameError
150
150
  end
151
151
  end
152
-
152
+
153
153
  assert_raises Validation::InvalidWritingError do
154
154
  sth.catch_error = obj
155
155
  end
@@ -157,9 +157,9 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
157
157
 
158
158
  def test_rescue
159
159
  sth = Sth.new
160
-
160
+
161
161
  obj = Object.new
162
-
162
+
163
163
  sth.rescue_error = obj
164
164
  assert_same obj, sth.rescue_error
165
165
  sth.rescue_error = false
@@ -172,15 +172,15 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
172
172
  assert_raises Validation::InvalidWritingError do
173
173
  sth.rescue_error = obj
174
174
  end
175
-
175
+
176
176
  obj.singleton_class.class_eval do
177
177
  remove_method :no_name!
178
-
178
+
179
179
  def no_name!
180
180
  raise NameError
181
181
  end
182
182
  end
183
-
183
+
184
184
  sth.rescue_error = obj
185
185
  end
186
186
 
@@ -190,7 +190,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
190
190
  assert_raises Validation::InvalidWritingError do
191
191
  sth.all_pass = 11
192
192
  end
193
-
193
+
194
194
  sth.all_pass = 1
195
195
  assert_equal 1, sth.all_pass
196
196
  sth.all_pass = 4
@@ -207,7 +207,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
207
207
  assert_raises Validation::InvalidWritingError do
208
208
  sth.has_ignore = 2
209
209
  end
210
-
210
+
211
211
  sth.has_ignore = 3
212
212
  assert_equal 3, sth.has_ignore
213
213
  assert_raises Validation::InvalidWritingError do
@@ -225,7 +225,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
225
225
  assert_raises Validation::InvalidWritingError do
226
226
  sth.nand = 4.5
227
227
  end
228
-
228
+
229
229
  sth.nand = 2
230
230
  assert_equal 2, sth.nand
231
231
  sth.nand = []
@@ -234,22 +234,22 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
234
234
 
235
235
  def test_member_of
236
236
  sth = Sth.new
237
-
237
+
238
238
  assert_raises Validation::InvalidWritingError do
239
239
  sth.one_of_member = 4
240
240
  end
241
-
241
+
242
242
  sth.one_of_member = 3
243
243
  assert_equal 3, sth.one_of_member
244
244
  end
245
-
245
+
246
246
  def test_generics
247
247
  sth = Sth.new
248
-
248
+
249
249
  assert_raises Validation::InvalidWritingError do
250
250
  sth.list_only_int = [1, '2']
251
251
  end
252
-
252
+
253
253
  sth.list_only_int = [1, 2]
254
254
  assert_equal [1, 2], sth.list_only_int
255
255
  sth.list_only_int = []
@@ -258,11 +258,11 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
258
258
 
259
259
  def test_all
260
260
  sth = Sth.new
261
-
261
+
262
262
  assert_raises Validation::InvalidWritingError do
263
263
  sth.list_only_int_2 = [1, '2']
264
264
  end
265
-
265
+
266
266
  sth.list_only_int_2 = [1, 2]
267
267
  assert_equal [1, 2], sth.list_only_int_2
268
268
  sth.list_only_int_2 = []
@@ -271,25 +271,25 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
271
271
 
272
272
  def test_boolean
273
273
  sth = Sth.new
274
-
274
+
275
275
  assert_raises Validation::InvalidWritingError do
276
276
  sth.true_or_false = nil
277
277
  end
278
-
278
+
279
279
  sth.true_or_false = true
280
280
  assert_equal true, sth.true_or_false
281
281
  sth.true_or_false = false
282
282
  assert_equal false, sth.true_or_false
283
283
  end
284
-
284
+
285
285
  def test_STRINGABLE?
286
286
  sth = Sth.new
287
287
  obj = Object.new
288
-
288
+
289
289
  assert_raises Validation::InvalidWritingError do
290
290
  sth.like_str = obj
291
291
  end
292
-
292
+
293
293
  obj.singleton_class.class_eval do
294
294
  def to_str
295
295
  end
@@ -299,20 +299,20 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
299
299
  def test_responsible_arg1
300
300
  sth = Sth.new
301
301
  obj = Object.new
302
-
302
+
303
303
  raise if obj.respond_to? :foo
304
304
 
305
305
  assert_raises Validation::InvalidWritingError do
306
306
  sth.has_foo = obj
307
307
  end
308
-
308
+
309
309
  obj.singleton_class.class_eval do
310
310
  def foo
311
311
  end
312
312
  end
313
313
 
314
314
  raise unless obj.respond_to? :foo
315
-
315
+
316
316
  sth.has_foo = obj
317
317
  assert_equal obj, sth.has_foo
318
318
  end
@@ -327,25 +327,25 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
327
327
  assert_raises Validation::InvalidWritingError do
328
328
  sth.has_foo_and_bar = obj
329
329
  end
330
-
330
+
331
331
  obj.singleton_class.class_eval do
332
332
  def foo
333
333
  end
334
334
  end
335
-
335
+
336
336
  raise unless obj.respond_to? :foo
337
337
 
338
338
  assert_raises Validation::InvalidWritingError do
339
339
  sth.has_foo_and_bar = obj
340
340
  end
341
-
341
+
342
342
  obj.singleton_class.class_eval do
343
343
  def bar
344
344
  end
345
345
  end
346
346
 
347
347
  raise unless obj.respond_to? :bar
348
-
348
+
349
349
  sth.has_foo_and_bar = obj
350
350
  assert_equal obj, sth.has_foo_and_bar
351
351
  end
@@ -356,7 +356,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
356
356
  assert_raises Validation::InvalidWritingError do
357
357
  sth.eq = (EQUALITY_CHECKER.dup << ':(')
358
358
  end
359
-
359
+
360
360
  sth.eq = EQUALITY_CHECKER.dup
361
361
  assert_equal EQUALITY_CHECKER, sth.eq
362
362
  end
@@ -367,7 +367,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
367
367
  assert_raises Validation::InvalidWritingError do
368
368
  sth.equal = EQUALITY_CHECKER.dup
369
369
  end
370
-
370
+
371
371
  sth.equal = EQUALITY_CHECKER
372
372
  assert_same EQUALITY_CHECKER, sth.equal
373
373
  end
@@ -378,7 +378,7 @@ class TestValidationSpecificConditions < Test::Unit::TestCase
378
378
  assert_raises Validation::InvalidWritingError do
379
379
  sth.same = EQUALITY_CHECKER.dup
380
380
  end
381
-
381
+
382
382
  sth.same = EQUALITY_CHECKER
383
383
  assert_same EQUALITY_CHECKER, sth.same
384
384
  end
@@ -387,28 +387,28 @@ end
387
387
  class TestGetterValidation < Test::Unit::TestCase
388
388
  class Sth
389
389
  include Validation
390
-
390
+
391
391
  attr_validator :plus_getter, /./, writer_validation: true, reader_validation: true
392
392
  attr_validator :only_getter, /./, writer_validation: false, reader_validation: true
393
393
  end
394
-
394
+
395
395
  def test_writer_validation
396
396
  sth = Sth.new
397
-
397
+
398
398
  assert_raises Validation::InvalidWritingError do
399
399
  sth.plus_getter = ''
400
400
  end
401
-
401
+
402
402
  sth.plus_getter = 'abc'
403
403
  assert_equal 'abc', sth.plus_getter
404
404
  sth.plus_getter.clear
405
-
405
+
406
406
  assert_raises Validation::InvalidReadingError do
407
407
  sth.plus_getter
408
408
  end
409
-
409
+
410
410
  sth.only_getter = ''
411
-
411
+
412
412
  assert_raises Validation::InvalidReadingError do
413
413
  sth.only_getter
414
414
  end
@@ -418,15 +418,15 @@ end
418
418
  class TestValidationAdjustmentOld < Test::Unit::TestCase
419
419
  class Sth
420
420
  include Validation
421
-
421
+
422
422
  attr_validator :age, Numeric, &->arg{Integer arg}
423
423
  end
424
-
424
+
425
425
  def setup
426
426
  @sth = Sth.new
427
427
  assert_same nil, @sth.age
428
428
  end
429
-
429
+
430
430
  def test_procedure
431
431
  @sth.age = 10
432
432
  assert_same 10, @sth.age
@@ -436,7 +436,7 @@ class TestValidationAdjustmentOld < Test::Unit::TestCase
436
436
  assert_raises Validation::InvalidAdjustingError do
437
437
  @sth.age = '10.0'
438
438
  end
439
-
439
+
440
440
  @sth.age = '10'
441
441
  assert_same 10, @sth.age
442
442
  end
@@ -449,7 +449,7 @@ class TestValidationAdjustment < Test::Unit::TestCase
449
449
  new
450
450
  end
451
451
  end
452
-
452
+
453
453
  class Sth
454
454
  include Validation
455
455
 
@@ -459,22 +459,22 @@ class TestValidationAdjustment < Test::Unit::TestCase
459
459
  attr_validator :integer, Integer, &PARSE(Integer)
460
460
  attr_validator :myobj, ->v{v.instance_of? MyClass}, &PARSE(MyClass)
461
461
  end
462
-
462
+
463
463
  def test_WHEN
464
464
  sth = Sth.new
465
-
465
+
466
466
  assert_raises Validation::InvalidWritingError do
467
467
  sth.chomped = :"a\n"
468
468
  end
469
-
469
+
470
470
  assert_raises Validation::InvalidAdjustingError do
471
471
  sth.chomped = 'a'
472
472
  end
473
473
 
474
474
  sth.chomped = :a
475
-
475
+
476
476
  assert_equal :a, sth.chomped
477
-
477
+
478
478
  sth.chomped = :b
479
479
  assert_equal :b, sth.chomped
480
480
  end
@@ -492,29 +492,29 @@ class TestValidationAdjustment < Test::Unit::TestCase
492
492
  assert_raises Validation::InvalidAdjustingError do
493
493
  sth.no_reduced = obj
494
494
  end
495
-
495
+
496
496
  sth.reduced = obj
497
-
497
+
498
498
  assert_equal :'This is strings :)', sth.reduced
499
499
  end
500
-
500
+
501
501
  def test_PARSE
502
502
  sth = Sth.new
503
-
503
+
504
504
  assert_raises Validation::InvalidAdjustingError do
505
505
  sth.integer = '1.0'
506
506
  end
507
-
507
+
508
508
  sth.integer = '1'
509
-
509
+
510
510
  assert_equal 1, sth.integer
511
-
511
+
512
512
  assert_raises Validation::InvalidAdjustingError do
513
513
  sth.myobj = '1'
514
514
  end
515
-
515
+
516
516
  sth.myobj = 'a'
517
-
517
+
518
518
  assert_kind_of MyClass, sth.myobj
519
519
  end
520
520
  end
@@ -1,26 +1,25 @@
1
1
  # coding: us-ascii
2
2
 
3
- require File.expand_path('../lib/validation/version', __FILE__)
3
+ lib_name = 'validation'.freeze
4
+ require "./lib/#{lib_name}/version"
4
5
 
5
6
  Gem::Specification.new do |gem|
6
7
  # specific
7
8
 
8
- gem.description = %q{A way of defining validations on anywhere.}
9
- gem.summary = %q{A way of defining validations on anywhere.}
10
- gem.homepage = 'http://kachick.github.com/validation/'
9
+ gem.description = %q{Validations with Ruby objects.}
10
+ gem.summary = gem.description.dup
11
+ gem.homepage = "http://kachick.github.com/#{lib_name}/"
11
12
  gem.license = 'MIT'
12
- gem.name = 'validation'
13
+ gem.name = lib_name.dup
13
14
  gem.version = Validation::VERSION.dup
14
15
 
15
- gem.required_ruby_version = '>= 1.9.3'
16
- gem.add_development_dependency 'yard', '>= 0.8.7.3', '< 0.9'
16
+ gem.required_ruby_version = '>= 1.9.3' # Tested in 2.2 or later version.
17
+ gem.add_development_dependency 'yard', '>= 0.9.9', '< 2'
17
18
  gem.add_development_dependency 'rake', '>= 10', '< 20'
18
- gem.add_development_dependency 'bundler', '>= 1.3.5', '< 2'
19
+ gem.add_development_dependency 'test-unit', '>= 3.2.6', '< 4'
19
20
 
20
21
  if RUBY_ENGINE == 'rbx'
21
- gem.add_dependency 'rubysl', '~> 2.0'
22
-
23
- gem.add_development_dependency 'test-unit', '>= 2.5.5', '< 2.6'
22
+ gem.add_dependency 'rubysl', '>= 2.2'
24
23
  end
25
24
 
26
25
  # common
@@ -32,4 +31,4 @@ Gem::Specification.new do |gem|
32
31
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
33
32
  gem.require_paths = ['lib']
34
33
 
35
- end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-05 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.7.3
19
+ version: 0.9.9
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.9'
22
+ version: '2'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.8.7.3
29
+ version: 0.9.9
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.9'
32
+ version: '2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -51,26 +51,26 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: '20'
53
53
  - !ruby/object:Gem::Dependency
54
- name: bundler
54
+ name: test-unit
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.3.5
59
+ version: 3.2.6
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '2'
62
+ version: '4'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 1.3.5
69
+ version: 3.2.6
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '2'
73
- description: A way of defining validations on anywhere.
72
+ version: '4'
73
+ description: Validations with Ruby objects.
74
74
  email:
75
75
  - kachick1+ruby@gmail.com
76
76
  executables: []
@@ -118,11 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.2.0
121
+ rubygems_version: 2.6.14
122
122
  signing_key:
123
123
  specification_version: 4
124
- summary: A way of defining validations on anywhere.
124
+ summary: Validations with Ruby objects.
125
125
  test_files:
126
126
  - test/test_helper.rb
127
127
  - test/test_validation.rb
128
- has_rdoc: