rasti-form 2.2.0 → 3.0.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: c52204d2ee5fd0dec69e737cb54dcaadc0e1aefa
4
- data.tar.gz: '08a1332b2f45c622de662393a551cda4797f1ce8'
3
+ metadata.gz: 9dd0424409c0c7232782c40cde8dbf7fa84752d3
4
+ data.tar.gz: a7c8be9e98dcc9e6d52482469486ba643a0ffa33
5
5
  SHA512:
6
- metadata.gz: d83646128669902f9d7bbfd367ac7b92f9a683258687675b15725f8fab3b0c6778f6fb1553f8c5b7149f419d9b2768f6a3004471ecb28b4b1463086bd6371af8
7
- data.tar.gz: 3600ad2b86770649044ce09d55025d6d1b51dda7e772f016c7bd7f134a634100b6e0d7bce45a3028071b51cf3762685109bfe6820cfc91e9aeb19a48c0f47fcc
6
+ metadata.gz: a2fb881aec7bca876dd58a3c2bf3e6dcca8ac3f13777437992f4e359d07856c9a7075e4b4c51882f41cb30ffacb8ebf85616632898efbfa02ccd7abea6a7e81c
7
+ data.tar.gz: c77fed8829801cae565a567f3303b8c4271e5a9b3b79c7ac2f04475e48a9bc6d884e80e2253903a0374a4848d635cf0576a1b191044c850f6cf9aea70a373416
data/README.md CHANGED
@@ -94,6 +94,7 @@ form.to # => 2016-10-28 00:00:00 -0300
94
94
  - Form
95
95
  - Hash
96
96
  - Integer
97
+ - IO
97
98
  - Regexp
98
99
  - String
99
100
  - Symbol
@@ -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
@@ -2,10 +2,17 @@ module Rasti
2
2
  class Form
3
3
  module Types
4
4
  class String
5
+
6
+ include Formatable
7
+
5
8
  class << self
6
9
 
7
10
  include Castable
8
-
11
+
12
+ def [](format)
13
+ new format
14
+ end
15
+
9
16
  private
10
17
 
11
18
  def valid?(value)
@@ -17,6 +24,20 @@ module Rasti
17
24
  end
18
25
 
19
26
  end
27
+
28
+ def to_s
29
+ "#{self.class}[#{format.inspect}]"
30
+ end
31
+ alias_method :inspect, :to_s
32
+
33
+ private
34
+
35
+ attr_reader :format
36
+
37
+ def initialize(format)
38
+ @format = format.is_a?(String) ? ::Regexp.new(format) : format
39
+ end
40
+
20
41
  end
21
42
  end
22
43
  end
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class Form
3
- VERSION = '2.2.0'
3
+ VERSION = '3.0.0'
4
4
  end
5
5
  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)
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
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.2.0
4
+ version: 3.0.0
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-10-01 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_require
@@ -191,6 +191,7 @@ files:
191
191
  - spec/types/integer_spec.rb
192
192
  - spec/types/io_spec.rb
193
193
  - spec/types/regexp_spec.rb
194
+ - spec/types/string_formatted_spec.rb
194
195
  - spec/types/string_spec.rb
195
196
  - spec/types/symbol_spec.rb
196
197
  - spec/types/time_spec.rb
@@ -232,6 +233,7 @@ test_files:
232
233
  - spec/types/integer_spec.rb
233
234
  - spec/types/io_spec.rb
234
235
  - spec/types/regexp_spec.rb
236
+ - spec/types/string_formatted_spec.rb
235
237
  - spec/types/string_spec.rb
236
238
  - spec/types/symbol_spec.rb
237
239
  - spec/types/time_spec.rb