attribeauty 0.3.3 → 0.3.4
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/CHANGELOG.md +4 -0
 - data/Gemfile.lock +1 -1
 - data/lib/attribeauty/params.rb +25 -18
 - data/lib/attribeauty/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 04be2abe193a7faca2c172bb90713086e2a656bada649e0356ada8a444f54993
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e86ca7fb0fbc2d8e20679be174a98eced95c6facf3d98d2b3d1983961e99a9c8
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1fe0d80aca7c85b8a34bf233f8b72133f16b75eea1a1800e8046efe5df1b19612a060662dc4c80bbbcffd0462d8cf2dee229a1c36228bba155dcff1058d814a7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 42ab8159a2117c43956b84699f7ba9025a156e854e355f389424b810ecdfa90ee83f2fbdbdf71b43b650f723d1310288c18dc0f1e03f0f4765f193a8d58a1cc0
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/attribeauty/params.rb
    CHANGED
    
    | 
         @@ -44,17 +44,13 @@ module Attribeauty 
     | 
|
| 
       44 
44 
     | 
    
         
             
                  yield
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                # 
         
     | 
| 
       47 
48 
     | 
    
         
             
                def attribute(name, type = nil, **args, &block)
         
     | 
| 
       48 
49 
     | 
    
         
             
                  value = request_params[name]
         
     | 
| 
       49 
     | 
    
         
            -
                  return if value 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                  else
         
     | 
| 
       54 
     | 
    
         
            -
                    validator = Validator.run(name, value, type, **args)
         
     | 
| 
       55 
     | 
    
         
            -
                    @errors.push(*validator.errors)
         
     | 
| 
       56 
     | 
    
         
            -
                    @to_h[name.to_sym] = validator.value if validator.valid?
         
     | 
| 
       57 
     | 
    
         
            -
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
                  return if required?(value, **args)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  return hash_from_nested(name, value, &block) if block_given?
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  value_from_validator(name, value, type, **args)
         
     | 
| 
       58 
54 
     | 
    
         
             
                end
         
     | 
| 
       59 
55 
     | 
    
         | 
| 
       60 
56 
     | 
    
         
             
                def inspect
         
     | 
| 
         @@ -71,17 +67,28 @@ module Attribeauty 
     | 
|
| 
       71 
67 
     | 
    
         | 
| 
       72 
68 
     | 
    
         
             
                private
         
     | 
| 
       73 
69 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
                def  
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                def required?(value, **args)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  value.nil? && args[:required].nil?
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                def value_from_validator(name, value, type, **args)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  validator = Validator.run(name, value, type, **args)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @errors.push(*validator.errors)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @to_h[name.to_sym] = validator.value if validator.valid?
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                def hash_from_nested(name, value, &block)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @to_h[name.to_sym] = 
         
     | 
| 
      
 82 
     | 
    
         
            +
                    if value.is_a?(Array)
         
     | 
| 
      
 83 
     | 
    
         
            +
                      value.map do |val|
         
     | 
| 
      
 84 
     | 
    
         
            +
                        params = self.class.with(val).accept(&block)
         
     | 
| 
      
 85 
     | 
    
         
            +
                        @errors.push(*params.errors)
         
     | 
| 
      
 86 
     | 
    
         
            +
                        params.to_h
         
     | 
| 
      
 87 
     | 
    
         
            +
                      end.reject(&:empty?)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    else
         
     | 
| 
      
 89 
     | 
    
         
            +
                      params = self.class.with(value).accept(&block)
         
     | 
| 
       78 
90 
     | 
    
         
             
                      @errors.push(*params.errors)
         
     | 
| 
       79 
91 
     | 
    
         
             
                      params.to_h
         
     | 
| 
       80 
     | 
    
         
            -
                    end.reject(&:empty?)
         
     | 
| 
       81 
     | 
    
         
            -
                  else
         
     | 
| 
       82 
     | 
    
         
            -
                    params = self.class.with(value).accept(&block)
         
     | 
| 
       83 
     | 
    
         
            -
                    @errors.push(*params.errors)
         
     | 
| 
       84 
     | 
    
         
            -
                    params.to_h
         
     | 
| 
       85 
92 
     | 
    
         
             
                  end
         
     | 
| 
       86 
93 
     | 
    
         
             
                end
         
     | 
| 
       87 
94 
     | 
    
         
             
              end
         
     | 
    
        data/lib/attribeauty/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: attribeauty
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Toby
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-06-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: There are so many of these, I just needed this one.
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |