rectify 0.9.1 → 0.10.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/lib/rectify/form.rb +14 -3
- data/lib/rectify/version.rb +1 -1
- data/readme.md +42 -5
- metadata +16 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 765fc6e3fd9b5d66f59f4a5c2b279f2eae06a5d7
         | 
| 4 | 
            +
              data.tar.gz: 41379b062e59c2be3be9507565704dc230b0191b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dfefaa5dd1fb1954cfabf1a1e86f5469c60c6329a8037ad99461ba375a5e1d80ec20ebf8a367c8647e10a86c895f04ee9a34fc6f9dc7c9bc6cd5dd7d0e5a31f1
         | 
| 7 | 
            +
              data.tar.gz: 8936f106a590145d25c12c661e337c0e906b5fefc81b7ac42eb7d2ef4ad14e4a54f121d8c5ccfd1879aa8b2f97d3e820ff37eb47449facf0d68808178aff453d
         | 
    
        data/lib/rectify/form.rb
    CHANGED
    
    | @@ -58,10 +58,21 @@ module Rectify | |
| 58 58 | 
             
                  id.present? && id.to_i > 0
         | 
| 59 59 | 
             
                end
         | 
| 60 60 |  | 
| 61 | 
            -
                def valid?( | 
| 61 | 
            +
                def valid?(options = {})
         | 
| 62 62 | 
             
                  before_validation
         | 
| 63 63 |  | 
| 64 | 
            -
                   | 
| 64 | 
            +
                  options     = {} if options.blank?
         | 
| 65 | 
            +
                  context     = options[:context]
         | 
| 66 | 
            +
                  validations = [super(context)]
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  validations << form_attributes_valid? unless options[:exclude_nested]
         | 
| 69 | 
            +
                  validations << array_attributes_valid? unless options[:exclude_arrays]
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  validations.all?
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                def invalid?(options = {})
         | 
| 75 | 
            +
                  !valid?(options)
         | 
| 65 76 | 
             
                end
         | 
| 66 77 |  | 
| 67 78 | 
             
                def to_key
         | 
| @@ -119,7 +130,7 @@ module Rectify | |
| 119 130 | 
             
                    .all?
         | 
| 120 131 | 
             
                end
         | 
| 121 132 |  | 
| 122 | 
            -
                def  | 
| 133 | 
            +
                def array_attributes_valid?
         | 
| 123 134 | 
             
                  array_attributes_that_respond_to(:valid?)
         | 
| 124 135 | 
             
                    .map(&:valid?)
         | 
| 125 136 | 
             
                    .all?
         | 
    
        data/lib/rectify/version.rb
    CHANGED
    
    
    
        data/readme.md
    CHANGED
    
    | @@ -371,6 +371,43 @@ your form as well as any (deeply) nested form objects and array attributes that | |
| 371 371 | 
             
            contain form objects. There is also an `#invalid?` method that returns the
         | 
| 372 372 | 
             
            opposite of `#valid?`.
         | 
| 373 373 |  | 
| 374 | 
            +
            The `#valid?` and `#invalid?` methods also take a set of options. These options allow
         | 
| 375 | 
            +
            you to not validate nested form objects or array attributes that contain form objects.
         | 
| 376 | 
            +
            For example:
         | 
| 377 | 
            +
             | 
| 378 | 
            +
            ```ruby
         | 
| 379 | 
            +
            class UserForm < Rectify::Form
         | 
| 380 | 
            +
              attribute :name,     String
         | 
| 381 | 
            +
              attribute :address,  AddressForm
         | 
| 382 | 
            +
              attribute :contacts, Array[ContactForm]
         | 
| 383 | 
            +
             | 
| 384 | 
            +
              validates :name, :presence => true
         | 
| 385 | 
            +
            end
         | 
| 386 | 
            +
             | 
| 387 | 
            +
            class AddressForm < Rectify::Form
         | 
| 388 | 
            +
              attribute :street,    String
         | 
| 389 | 
            +
              attribute :town,      String
         | 
| 390 | 
            +
              attribute :city,      String
         | 
| 391 | 
            +
              attribute :post_code, String
         | 
| 392 | 
            +
             | 
| 393 | 
            +
              validates :street, :post_code, :presence => true
         | 
| 394 | 
            +
            end
         | 
| 395 | 
            +
             | 
| 396 | 
            +
            class ContactForm < Rectify::Form
         | 
| 397 | 
            +
              attribute :name,   String
         | 
| 398 | 
            +
              attribute :number, String
         | 
| 399 | 
            +
             | 
| 400 | 
            +
              validates :name, :presence => true
         | 
| 401 | 
            +
            end
         | 
| 402 | 
            +
             | 
| 403 | 
            +
            form = UserForm.from_params(params)
         | 
| 404 | 
            +
             | 
| 405 | 
            +
            form.valid?(:exclude_nested => true, :exclude_arrays => true)
         | 
| 406 | 
            +
            ```
         | 
| 407 | 
            +
             | 
| 408 | 
            +
            In this case, the `UserForm` attributes will be validated (`name` in the example above)
         | 
| 409 | 
            +
            but the `address` and `contacts` will not be validated.
         | 
| 410 | 
            +
             | 
| 374 411 | 
             
            ### Deep Context
         | 
| 375 412 |  | 
| 376 413 | 
             
            It's sometimes useful to have some context within your form objects when performing
         | 
| @@ -1054,11 +1091,11 @@ application. Something like the following: | |
| 1054 1091 | 
             
            └── app
         | 
| 1055 1092 | 
             
                ├── controllers
         | 
| 1056 1093 | 
             
                ├── core
         | 
| 1057 | 
            -
                │ | 
| 1058 | 
            -
                │ | 
| 1059 | 
            -
                │ | 
| 1060 | 
            -
                │ | 
| 1061 | 
            -
                │ | 
| 1094 | 
            +
                │   ├── billing
         | 
| 1095 | 
            +
                │   ├── fulfillment
         | 
| 1096 | 
            +
                │   ├── ordering
         | 
| 1097 | 
            +
                │   ├── reporting
         | 
| 1098 | 
            +
                │   └── security
         | 
| 1062 1099 | 
             
                ├── models
         | 
| 1063 1100 | 
             
                └── views
         | 
| 1064 1101 | 
             
            ```
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rectify
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andy Pike
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-08-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: virtus
         | 
| @@ -178,6 +178,20 @@ dependencies: | |
| 178 178 | 
             
                - - ">="
         | 
| 179 179 | 
             
                  - !ruby/object:Gem::Version
         | 
| 180 180 | 
             
                    version: '0'
         | 
| 181 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 182 | 
            +
              name: rubocop
         | 
| 183 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 184 | 
            +
                requirements:
         | 
| 185 | 
            +
                - - ">="
         | 
| 186 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 187 | 
            +
                    version: '0'
         | 
| 188 | 
            +
              type: :development
         | 
| 189 | 
            +
              prerelease: false
         | 
| 190 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 191 | 
            +
                requirements:
         | 
| 192 | 
            +
                - - ">="
         | 
| 193 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 194 | 
            +
                    version: '0'
         | 
| 181 195 | 
             
            description: Build Rails apps in a more maintainable way
         | 
| 182 196 | 
             
            email: andy@andypike.com
         | 
| 183 197 | 
             
            executables: []
         |