rasti-form 2.0.0 → 3.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
- SHA1:
3
- metadata.gz: 26c1c1f5dc1233ecbda35f3e19c0a6b8e286405c
4
- data.tar.gz: 465729370df0070a7c536b6fc39c11d92a3b27fc
2
+ SHA256:
3
+ metadata.gz: 30eebb17e0a18f1c4ea84fb4dc617742325e38876cb03f6b85af4a29b2a6bcd6
4
+ data.tar.gz: 2e3ebc2338f62e608cec51a596db988b3f59751be11572a92216542f37fbb23f
5
5
  SHA512:
6
- metadata.gz: ae1a7c147d82af7c2a3095a682e80899746fcc3b00aa44a0c4fb88842895f01daf577056be8b1eaa06351c0e85c12a03f4d0abe82db0ec910c97f789c98deb58
7
- data.tar.gz: 40e2ffc9f4287a1c726c15f469575c5ed14bef3ae8a5f47eef0a49abd97b4ea127e78544cb831c7cf834bac2f1aedb30f717aba5aa1c75374847d388eb715a98
6
+ metadata.gz: dc4a4484961c15e7b054d5aabadcacf61a4ec2e9d40973ee8f226dc3bcb62bd2c46a07e710c84bfb97bfe31fd78bef256009ec34b554f789ea1e4f6c3ea7d57b
7
+ data.tar.gz: 5e46bfdfdd2a5cf657f30e901cd68dd43f8aefada51c1fbfd52a9eee09bf1bb232c0f86f07a4bf67430dbbc48e8043d9b1e50157a0cc620fa37d249675ac3bc4
@@ -1 +1 @@
1
- ruby-2.4.0
1
+ ruby-2.5.7
@@ -1,15 +1,15 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
4
  - 2.0
6
5
  - 2.1
7
6
  - 2.2
8
- - 2.3.0
9
- - 2.4.0
10
- - 2.5.0
11
- - jruby-1.7.25
12
- - jruby-9.1.7.0
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ - 2.6
11
+ - 2.7
12
+ - jruby-9.2.9.0
13
13
  - ruby-head
14
14
  - jruby-head
15
15
 
@@ -17,7 +17,4 @@ matrix:
17
17
  fast_finish: true
18
18
  allow_failures:
19
19
  - rvm: ruby-head
20
- - rvm: jruby-head
21
-
22
- before_install:
23
- - gem install bundler
20
+ - rvm: jruby-head
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Build Status](https://travis-ci.org/gabynaiman/rasti-form.svg?branch=master)](https://travis-ci.org/gabynaiman/rasti-form)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/gabynaiman/rasti-form/badge.svg?branch=master)](https://coveralls.io/github/gabynaiman/rasti-form?branch=master)
6
6
  [![Code Climate](https://codeclimate.com/github/gabynaiman/rasti-form.svg)](https://codeclimate.com/github/gabynaiman/rasti-form)
7
- [![Dependency Status](https://gemnasium.com/gabynaiman/rasti-form.svg)](https://gemnasium.com/gabynaiman/rasti-form)
8
7
 
9
8
  Forms validations and type casting
10
9
 
@@ -94,6 +93,7 @@ form.to # => 2016-10-28 00:00:00 -0300
94
93
  - Form
95
94
  - Hash
96
95
  - Integer
96
+ - IO
97
97
  - Regexp
98
98
  - String
99
99
  - Symbol
@@ -18,13 +18,13 @@ module Rasti
18
18
  attributes.each do |name, type, options={}|
19
19
  attribute name, type, options
20
20
  end
21
-
22
- def self.inherited(subclass)
23
- subclass.instance_variable_set :@attributes, attributes.dup
24
- end
25
21
  end
26
22
  end
27
23
 
24
+ def inherited(subclass)
25
+ subclass.instance_variable_set :@attributes, attributes.dup
26
+ end
27
+
28
28
  def attribute(name, type, options={})
29
29
  attributes[name.to_sym] = options.merge(type: type)
30
30
  attr_reader name
@@ -145,7 +145,11 @@ module Rasti
145
145
  end
146
146
 
147
147
  def assert_present(attribute)
148
- assert attribute, !fetch(attribute).nil?, 'not present'
148
+ assert attribute, !fetch(attribute).nil?, 'not present' unless errors.key? attribute
149
+ end
150
+
151
+ def assert_not_present(attribute)
152
+ assert attribute, fetch(attribute).nil?, 'is present'
149
153
  end
150
154
 
151
155
  def assert_not_empty(attribute)
@@ -155,6 +159,10 @@ module Rasti
155
159
  end
156
160
  end
157
161
 
162
+ def assert_time_range(attribute_from, attribute_to)
163
+ assert attribute_from, public_send(attribute_from) <= public_send(attribute_to), 'invalid time range'
164
+ end
165
+
158
166
  def assert_included_in(attribute, set)
159
167
  if assert_present attribute
160
168
  assert attribute, set.include?(fetch(attribute)), "not included in #{set.map { |e| e.is_a?(::String) ? "'#{e}'" : e.inspect }.join(', ')}"
@@ -53,7 +53,15 @@ module Rasti
53
53
  end
54
54
 
55
55
  def message
56
- "Validation error: #{scope} #{JSON.dump(errors)}"
56
+ lines = ['Validation errors:']
57
+
58
+ errors.each do |key, value|
59
+ lines << "- #{key}: #{value}"
60
+ end
61
+
62
+ lines << scope.inspect
63
+
64
+ lines.join("\n")
57
65
  end
58
66
 
59
67
  end
@@ -0,0 +1,23 @@
1
+ module Rasti
2
+ class Form
3
+ module Types
4
+ class IO
5
+ class << self
6
+
7
+ include Castable
8
+
9
+ private
10
+
11
+ def valid?(value)
12
+ value.respond_to?(:read) && value.respond_to?(:write)
13
+ end
14
+
15
+ def transform(value)
16
+ value
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -2,26 +2,21 @@ module Rasti
2
2
  class Form
3
3
  module Types
4
4
  class Regexp
5
+ class << self
5
6
 
6
- include Formatable
7
+ include Castable
7
8
 
8
- def self.[](format)
9
- new format
10
- end
9
+ private
11
10
 
12
- def to_s
13
- "#{self.class}[#{format.inspect}]"
14
- end
15
- alias_method :inspect, :to_s
11
+ def valid?(value)
12
+ value.is_a?(::Regexp) || value.is_a?(::String)
13
+ end
16
14
 
17
- private
18
-
19
- attr_reader :format
15
+ def transform(value)
16
+ value.is_a?(::Regexp) ? value.source : ::Regexp.compile(value).source
17
+ end
20
18
 
21
- def initialize(format)
22
- @format = format.is_a?(String) ? ::Regexp.new(format) : format
23
19
  end
24
-
25
20
  end
26
21
  end
27
22
  end
@@ -5,11 +5,28 @@ module Rasti
5
5
  class << self
6
6
 
7
7
  include Castable
8
-
8
+
9
+ def [](format)
10
+ Class.new(self) do
11
+ @format = format.is_a?(::String) ? ::Regexp.new(format) : format
12
+ end
13
+ end
14
+
15
+ def to_s
16
+ name || "#{superclass.name}[#{format.inspect}]"
17
+ end
18
+ alias_method :inspect, :to_s
19
+
9
20
  private
10
21
 
22
+ attr_reader :format
23
+
11
24
  def valid?(value)
12
- !value.nil? && value.respond_to?(:to_s)
25
+ !value.nil? && value.respond_to?(:to_s) && valid_format?(value)
26
+ end
27
+
28
+ def valid_format?(value)
29
+ format.nil? || !value.to_s.match(format).nil?
13
30
  end
14
31
 
15
32
  def transform(value)
@@ -1,19 +1,7 @@
1
1
  module Rasti
2
2
  class Form
3
3
  module Types
4
- class UUID
5
- class << self
6
-
7
- include Formatable
8
-
9
- private
10
-
11
- def format
12
- /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}+$/
13
- end
14
-
15
- end
16
- end
4
+ UUID = String[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}+$/]
17
5
  end
18
6
  end
19
7
  end
@@ -23,6 +23,13 @@ module Rasti
23
23
  false
24
24
  end
25
25
 
26
+ def assert_not_error(key)
27
+ yield
28
+ true
29
+ rescue => error
30
+ assert key, false, error.message
31
+ end
32
+
26
33
  end
27
34
  end
28
35
  end
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class Form
3
- VERSION = '2.0.0'
3
+ VERSION = '3.1.1'
4
4
  end
5
5
  end
@@ -20,8 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'multi_require', '~> 1.0'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.12'
24
- spec.add_development_dependency 'rake', '~> 11.0'
23
+ spec.add_development_dependency 'rake', '~> 12.0'
25
24
  spec.add_development_dependency 'minitest', '~> 5.0', '< 5.11'
26
25
  spec.add_development_dependency 'minitest-colorin', '~> 0.1'
27
26
  spec.add_development_dependency 'minitest-line', '~> 0.6'
@@ -8,7 +8,7 @@ describe Rasti::Form do
8
8
 
9
9
  def build_form(&block)
10
10
  Class.new(Rasti::Form) do
11
- class_eval &block
11
+ class_eval(&block)
12
12
  end
13
13
  end
14
14
 
@@ -40,7 +40,7 @@ describe Rasti::Form do
40
40
 
41
41
  it 'Invalid attributes' do
42
42
  error = proc { point_class.new z: 3 }.must_raise Rasti::Form::ValidationError
43
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"z":["unexpected attribute"]}'
43
+ error.message.must_equal "Validation errors:\n- z: [\"unexpected attribute\"]\n#<Rasti::Form[]>"
44
44
  end
45
45
 
46
46
  describe 'Casting' do
@@ -86,7 +86,7 @@ describe Rasti::Form do
86
86
  end
87
87
 
88
88
  error = proc { form.new boolean: 'x', number: 'y' }.must_raise Rasti::Form::ValidationError
89
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"boolean":["Invalid cast: \'x\' -> Rasti::Form::Types::Boolean"],"number":["Invalid cast: \'y\' -> Rasti::Form::Types::Integer"]}'
89
+ error.message.must_equal "Validation errors:\n- boolean: [\"Invalid cast: \'x\' -> Rasti::Form::Types::Boolean\"]\n- number: [\"Invalid cast: \'y\' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
90
90
  end
91
91
 
92
92
  it 'Invalid nested attributes' do
@@ -95,7 +95,7 @@ describe Rasti::Form do
95
95
  end
96
96
 
97
97
  error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
98
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
98
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
99
99
  end
100
100
 
101
101
  it 'Invalid form attributes' do
@@ -109,7 +109,7 @@ describe Rasti::Form do
109
109
  end
110
110
 
111
111
  error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
112
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
112
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
113
113
  end
114
114
 
115
115
  end
@@ -141,6 +141,23 @@ describe Rasti::Form do
141
141
 
142
142
  describe 'Validations' do
143
143
 
144
+ it 'Not error' do
145
+ form = build_form do
146
+ attribute :text, Rasti::Form::Types::String
147
+
148
+ def validate
149
+ assert_not_error :text do
150
+ raise 'Invalid text' if text.nil?
151
+ end
152
+ end
153
+ end
154
+
155
+ proc { form.new text: 'text' }.must_be_silent
156
+
157
+ error = proc { form.new }.must_raise Rasti::Form::ValidationError
158
+ error.message.must_equal "Validation errors:\n- text: [\"Invalid text\"]\n#<Rasti::Form[]>"
159
+ end
160
+
144
161
  it 'Required' do
145
162
  form = build_form do
146
163
  attribute :text, Rasti::Form::Types::String
@@ -150,8 +167,40 @@ describe Rasti::Form do
150
167
  end
151
168
  end
152
169
 
170
+ proc { form.new text: 'text' }.must_be_silent
171
+
153
172
  error = proc { form.new }.must_raise Rasti::Form::ValidationError
154
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"text":["not present"]}'
173
+ error.message.must_equal "Validation errors:\n- text: [\"not present\"]\n#<Rasti::Form[]>"
174
+ end
175
+
176
+ it 'Required when cast failed' do
177
+ form = build_form do
178
+ attribute :number, Rasti::Form::Types::Integer
179
+
180
+ def validate
181
+ assert_present :number
182
+ end
183
+ end
184
+
185
+ proc { form.new number: 1 }.must_be_silent
186
+
187
+ error = proc { form.new number: 'text' }.must_raise Rasti::Form::ValidationError
188
+ error.message.must_equal "Validation errors:\n- number: [\"Invalid cast: 'text' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
189
+ end
190
+
191
+ it 'Not required' do
192
+ form = build_form do
193
+ attribute :text, Rasti::Form::Types::String
194
+
195
+ def validate
196
+ assert_not_present :text
197
+ end
198
+ end
199
+
200
+ proc { form.new }.must_be_silent
201
+
202
+ error = proc { form.new text: 'text' }.must_raise Rasti::Form::ValidationError
203
+ error.message.must_equal "Validation errors:\n- text: [\"is present\"]\n#<Rasti::Form[text: \"text\"]>"
155
204
  end
156
205
 
157
206
  it 'Not empty string' do
@@ -163,8 +212,10 @@ describe Rasti::Form do
163
212
  end
164
213
  end
165
214
 
215
+ proc { form.new text: 'text' }.must_be_silent
216
+
166
217
  error = proc { form.new text: ' ' }.must_raise Rasti::Form::ValidationError
167
- error.message.must_equal 'Validation error: #<Rasti::Form[text: " "]> {"text":["is empty"]}'
218
+ error.message.must_equal "Validation errors:\n- text: [\"is empty\"]\n#<Rasti::Form[text: \" \"]>"
168
219
  end
169
220
 
170
221
  it 'Not empty array' do
@@ -176,8 +227,10 @@ describe Rasti::Form do
176
227
  end
177
228
  end
178
229
 
230
+ proc { form.new array: ['text'] }.must_be_silent
231
+
179
232
  error = proc { form.new array: [] }.must_raise Rasti::Form::ValidationError
180
- error.message.must_equal 'Validation error: #<Rasti::Form[array: []]> {"array":["is empty"]}'
233
+ error.message.must_equal "Validation errors:\n- array: [\"is empty\"]\n#<Rasti::Form[array: []]>"
181
234
  end
182
235
 
183
236
  it 'Included in values list' do
@@ -189,8 +242,29 @@ describe Rasti::Form do
189
242
  end
190
243
  end
191
244
 
245
+ proc { form.new text: 'value_1' }.must_be_silent
246
+
192
247
  error = proc { form.new text: 'xyz' }.must_raise Rasti::Form::ValidationError
193
- error.message.must_equal 'Validation error: #<Rasti::Form[text: "xyz"]> {"text":["not included in \'value_1\', \'value_2\'"]}'
248
+ error.message.must_equal "Validation errors:\n- text: [\"not included in \'value_1\', \'value_2\'\"]\n#<Rasti::Form[text: \"xyz\"]>"
249
+ end
250
+
251
+ it 'Time range' do
252
+ form = build_form do
253
+ attribute :from, Rasti::Form::Types::Time['%Y-%m-%d %H:%M:%S %Z']
254
+ attribute :to, Rasti::Form::Types::Time['%Y-%m-%d %H:%M:%S %Z']
255
+
256
+ def validate
257
+ assert_time_range :from, :to
258
+ end
259
+ end
260
+
261
+ from = Time.parse '2018-01-01 03:10:00'
262
+ to = Time.parse '2018-01-01 15:30:00'
263
+
264
+ proc { form.new from: from, to: to }.must_be_silent
265
+
266
+ error = proc { form.new from: to.to_s, to: from.to_s }.must_raise Rasti::Form::ValidationError
267
+ error.message.must_equal "Validation errors:\n- from: [\"invalid time range\"]\n#<Rasti::Form[from: #{to}, to: #{from}]>"
194
268
  end
195
269
 
196
270
  it 'Nested form' do
@@ -203,8 +277,10 @@ describe Rasti::Form do
203
277
  end
204
278
  end
205
279
 
280
+ proc { form.new range: {min: 1, max: 2} }.must_be_silent
281
+
206
282
  error = proc { form.new }.must_raise Rasti::Form::ValidationError
207
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["not present"],"range.max":["not present"]}'
283
+ error.message.must_equal "Validation errors:\n- range.min: [\"not present\"]\n- range.max: [\"not present\"]\n#<Rasti::Form[]>"
208
284
  end
209
285
 
210
286
  it 'Nested validation' do
@@ -219,10 +295,12 @@ describe Rasti::Form do
219
295
 
220
296
  form = build_form do
221
297
  attribute :range, Rasti::Form::Types::Form[range]
222
- end
298
+ end
299
+
300
+ proc { form.new range: {min: 1, max: 2} }.must_be_silent
223
301
 
224
302
  error = proc { form.new range: {min: 2, max: 1} }.must_raise Rasti::Form::ValidationError
225
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["Min must be less than Max"]}'
303
+ error.message.must_equal "Validation errors:\n- range.min: [\"Min must be less than Max\"]\n#<Rasti::Form[]>"
226
304
  end
227
305
 
228
306
  end
@@ -46,7 +46,7 @@ describe Rasti::Form::Types::Array do
46
46
 
47
47
  error.errors.must_equal 'points.2.x' => ["Invalid cast: 'a' -> Rasti::Form::Types::Integer"],
48
48
  'points.3.y' => ["Invalid cast: 'b' -> Rasti::Form::Types::Integer"]
49
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"points.2.x\":[\"Invalid cast: 'a' -> Rasti::Form::Types::Integer\"],\"points.3.y\":[\"Invalid cast: 'b' -> Rasti::Form::Types::Integer\"]}"
49
+ error.message.must_equal "Validation errors:\n- points.2.x: [\"Invalid cast: 'a' -> Rasti::Form::Types::Integer\"]\n- points.3.y: [\"Invalid cast: 'b' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
50
50
  end
51
51
 
52
52
  end
@@ -35,7 +35,7 @@ describe Rasti::Form::Types::Form do
35
35
 
36
36
  it '{x: "text"} -> ValidationError' do
37
37
  error = proc { Rasti::Form::Types::Form[form].cast x: 'test' }.must_raise Rasti::Form::ValidationError
38
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"x\":[\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]}"
38
+ error.message.must_equal "Validation errors:\n- x: [\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
39
39
  end
40
40
 
41
41
  end
@@ -0,0 +1,18 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Rasti::Form::Types::IO do
4
+
5
+ [StringIO.new, File.new(__FILE__)].each do |value|
6
+ it "#{value.inspect} -> #{value}" do
7
+ Rasti::Form::Types::IO.cast(value).must_equal value
8
+ end
9
+ end
10
+
11
+ [nil, 'text', 123, :symbol, [1,2], {a: 1, b: 2}, Object.new].each do |value|
12
+ it "#{value.inspect} -> CastError" do
13
+ error = proc { Rasti::Form::Types::IO.cast(value) }.must_raise Rasti::Form::CastError
14
+ error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::IO"
15
+ end
16
+ end
17
+
18
+ end
@@ -2,18 +2,16 @@ require 'minitest_helper'
2
2
 
3
3
  describe Rasti::Form::Types::Regexp do
4
4
 
5
- email_regexp = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
6
-
7
- ['user@mail.com'.to_sym, 'user.name-123@mail-test.com.ar'].each do |value|
8
- it "#{value.inspect} -> #{value.to_s}" do
9
- Rasti::Form::Types::Regexp[email_regexp].cast(value).must_equal value
5
+ ['[a-z]', /[a-z]/].each do |value|
6
+ it "#{value.inspect} -> #{Regexp.new(value).inspect}" do
7
+ Rasti::Form::Types::Regexp.cast(value).must_equal Regexp.new(value).source
10
8
  end
11
9
  end
12
10
 
13
- [nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
11
+ [nil, '[a-z', :symbol, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
14
12
  it "#{value.inspect} -> CastError" do
15
- error = proc { Rasti::Form::Types::Regexp[email_regexp].cast(value) }.must_raise Rasti::Form::CastError
16
- error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Regexp[#{as_string(email_regexp)}]"
13
+ error = proc { Rasti::Form::Types::Regexp.cast(value) }.must_raise Rasti::Form::CastError
14
+ error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Regexp"
17
15
  end
18
16
  end
19
17
 
@@ -0,0 +1,20 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Rasti::Form::Types::String, 'Formatted' do
4
+
5
+ email_regexp = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
6
+
7
+ ['user@mail.com'.to_sym, 'user.name-123@mail-test.com.ar'].each do |value|
8
+ it "#{value.inspect} -> #{value.to_s}" do
9
+ Rasti::Form::Types::String[email_regexp].cast(value).must_equal value.to_s
10
+ end
11
+ end
12
+
13
+ [nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
14
+ it "#{value.inspect} -> CastError" do
15
+ error = proc { Rasti::Form::Types::String[email_regexp].cast(value) }.must_raise Rasti::Form::CastError
16
+ error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::String[#{as_string(email_regexp)}]"
17
+ end
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasti-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_require
@@ -24,34 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.12'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.12'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '11.0'
33
+ version: '12.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '11.0'
40
+ version: '12.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +148,6 @@ files:
162
148
  - lib/rasti/form.rb
163
149
  - lib/rasti/form/castable.rb
164
150
  - lib/rasti/form/errors.rb
165
- - lib/rasti/form/formatable.rb
166
151
  - lib/rasti/form/types/array.rb
167
152
  - lib/rasti/form/types/boolean.rb
168
153
  - lib/rasti/form/types/enum.rb
@@ -170,6 +155,7 @@ files:
170
155
  - lib/rasti/form/types/form.rb
171
156
  - lib/rasti/form/types/hash.rb
172
157
  - lib/rasti/form/types/integer.rb
158
+ - lib/rasti/form/types/io.rb
173
159
  - lib/rasti/form/types/regexp.rb
174
160
  - lib/rasti/form/types/string.rb
175
161
  - lib/rasti/form/types/symbol.rb
@@ -188,7 +174,9 @@ files:
188
174
  - spec/types/form_spec.rb
189
175
  - spec/types/hash_spec.rb
190
176
  - spec/types/integer_spec.rb
177
+ - spec/types/io_spec.rb
191
178
  - spec/types/regexp_spec.rb
179
+ - spec/types/string_formatted_spec.rb
192
180
  - spec/types/string_spec.rb
193
181
  - spec/types/symbol_spec.rb
194
182
  - spec/types/time_spec.rb
@@ -212,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
200
  - !ruby/object:Gem::Version
213
201
  version: '0'
214
202
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.6.8
203
+ rubygems_version: 3.0.6
217
204
  signing_key:
218
205
  specification_version: 4
219
206
  summary: Forms validations and type casting
@@ -228,7 +215,9 @@ test_files:
228
215
  - spec/types/form_spec.rb
229
216
  - spec/types/hash_spec.rb
230
217
  - spec/types/integer_spec.rb
218
+ - spec/types/io_spec.rb
231
219
  - spec/types/regexp_spec.rb
220
+ - spec/types/string_formatted_spec.rb
232
221
  - spec/types/string_spec.rb
233
222
  - spec/types/symbol_spec.rb
234
223
  - spec/types/time_spec.rb
@@ -1,19 +0,0 @@
1
- module Rasti
2
- class Form
3
- module Formatable
4
-
5
- include Castable
6
-
7
- private
8
-
9
- def valid?(value)
10
- (value.is_a?(::String) || value.is_a?(Symbol)) && value.to_s.match(format)
11
- end
12
-
13
- def transform(value)
14
- value
15
- end
16
-
17
- end
18
- end
19
- end