rasti-form 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +1 -0
 - data/lib/rasti/form/types/regexp.rb +9 -14
 - data/lib/rasti/form/types/string.rb +22 -1
 - data/lib/rasti/form/version.rb +1 -1
 - data/spec/types/regexp_spec.rb +6 -8
 - data/spec/types/string_formatted_spec.rb +20 -0
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9dd0424409c0c7232782c40cde8dbf7fa84752d3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a7c8be9e98dcc9e6d52482469486ba643a0ffa33
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a2fb881aec7bca876dd58a3c2bf3e6dcca8ac3f13777437992f4e359d07856c9a7075e4b4c51882f41cb30ffacb8ebf85616632898efbfa02ccd7abea6a7e81c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c77fed8829801cae565a567f3303b8c4271e5a9b3b79c7ac2f04475e48a9bc6d884e80e2253903a0374a4848d635cf0576a1b191044c850f6cf9aea70a373416
         
     | 
    
        data/README.md
    CHANGED
    
    
| 
         @@ -2,26 +2,21 @@ module Rasti 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Form
         
     | 
| 
       3 
3 
     | 
    
         
             
                module Types
         
     | 
| 
       4 
4 
     | 
    
         
             
                  class Regexp
         
     | 
| 
      
 5 
     | 
    
         
            +
                    class << self
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                      include Castable
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                      new format
         
     | 
| 
       10 
     | 
    
         
            -
                    end
         
     | 
| 
      
 9 
     | 
    
         
            +
                      private
         
     | 
| 
       11 
10 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                    alias_method :inspect, :to_s
         
     | 
| 
      
 11 
     | 
    
         
            +
                      def valid?(value)
         
     | 
| 
      
 12 
     | 
    
         
            +
                        value.is_a?(::Regexp) || value.is_a?(::String)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      end
         
     | 
| 
       16 
14 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
    
        data/lib/rasti/form/version.rb
    CHANGED
    
    
    
        data/spec/types/regexp_spec.rb
    CHANGED
    
    | 
         @@ -2,18 +2,16 @@ require 'minitest_helper' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe Rasti::Form::Types::Regexp do
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       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, ' 
     | 
| 
      
 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 
     | 
| 
       16 
     | 
    
         
            -
                  error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::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:  
     | 
| 
      
 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:  
     | 
| 
      
 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
         
     |