virtus 1.0.5 → 2.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 +5 -5
- data/.travis.yml +14 -15
- data/Changelog.md +10 -0
- data/Gemfile +4 -15
- data/README.md +15 -5
- data/lib/virtus.rb +19 -1
- data/lib/virtus/attribute.rb +2 -2
- data/lib/virtus/attribute/builder.rb +1 -7
- data/lib/virtus/attribute/collection.rb +5 -0
- data/lib/virtus/attribute/default_value.rb +2 -0
- data/lib/virtus/builder.rb +1 -5
- data/lib/virtus/class_inclusions.rb +0 -1
- data/lib/virtus/coercer.rb +1 -0
- data/lib/virtus/extensions.rb +13 -21
- data/lib/virtus/instance_methods.rb +1 -1
- data/lib/virtus/model.rb +1 -3
- data/lib/virtus/support/options.rb +1 -1
- data/lib/virtus/version.rb +1 -1
- data/spec/integration/attributes_attribute_spec.rb +28 -0
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/virtus/attribute/collection/value_coerced_predicate_spec.rb +31 -0
- data/spec/unit/virtus/attribute/comparison_spec.rb +20 -0
- data/spec/unit/virtus/attribute_set/append_spec.rb +4 -4
- data/spec/unit/virtus/attribute_set/element_set_spec.rb +15 -7
- data/spec/unit/virtus/attribute_set/merge_spec.rb +5 -3
- data/virtus.gemspec +1 -1
- metadata +10 -29
- data/.ruby-version +0 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 51fade6650444cdaba10d9fee1ab99f7a5707ddacbdb9c08a734dc415c6a7af8
         | 
| 4 | 
            +
              data.tar.gz: e8569ca6dc7f6b3bbbe6a00e1be51882dd3135b5e27ba218536f2409a3f495ec
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 289ce0a7a1d1841d832df7644fe1aa4d0202dd906161fb3b3704d0823ea1adb113976e0320505d8ea9ed2e8d00beb97ba235def16c4760ec9f384ceff3a3cdaf
         | 
| 7 | 
            +
              data.tar.gz: 7a0b0d652a88006bd1b5cd1e24157eb96700e788e6e2f6dc5e4d442f838a2fb59274f918aaab1ac93f042d0268bbd5bcee484e2e80cf2b3eeaacfb34f7448a00
         | 
    
        data/.travis.yml
    CHANGED
    
    | @@ -1,22 +1,21 @@ | |
| 1 | 
            +
            sudo: false
         | 
| 1 2 | 
             
            language: ruby
         | 
| 2 | 
            -
            before_install: gem install bundler
         | 
| 3 3 | 
             
            bundler_args: --without tools
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            env:
         | 
| 6 | 
            -
              - CODECLIMATE_REPO_TOKEN=2b66fbb7c7c72503eb7841a479c0ad923f691729f4109b4aa8c9b4def1ebb42d
         | 
| 4 | 
            +
            cache: bundler
         | 
| 7 5 | 
             
            rvm:
         | 
| 8 | 
            -
              - 1.9
         | 
| 9 6 | 
             
              - 2.0
         | 
| 10 7 | 
             
              - 2.1
         | 
| 11 8 | 
             
              - 2.2
         | 
| 9 | 
            +
              - 2.3
         | 
| 10 | 
            +
              - 2.4
         | 
| 11 | 
            +
              - 2.5
         | 
| 12 | 
            +
              - 2.6
         | 
| 13 | 
            +
              - 2.7
         | 
| 14 | 
            +
              - 3.0
         | 
| 12 15 | 
             
              - jruby
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              -  | 
| 15 | 
            -
             | 
| 16 | 
            -
               | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
            notifications:
         | 
| 20 | 
            -
              email:
         | 
| 21 | 
            -
                - piotr.solnica@gmail.com
         | 
| 22 | 
            -
                - dan.kubb@gmail.com
         | 
| 16 | 
            +
            before_script:
         | 
| 17 | 
            +
              - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
         | 
| 18 | 
            +
              - chmod +x ./cc-test-reporter
         | 
| 19 | 
            +
              - ./cc-test-reporter before-build
         | 
| 20 | 
            +
            after_script:
         | 
| 21 | 
            +
              - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
         | 
    
        data/Changelog.md
    CHANGED
    
    | @@ -1,3 +1,13 @@ | |
| 1 | 
            +
            # v2.0.0 2021-06-07
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * [added] New method `Virtus::Atrribute::Collection#value_coerced?`  (dslh)
         | 
| 4 | 
            +
            * [changed] inflecto was replaced with dry-inflector (solnic)
         | 
| 5 | 
            +
            * [changed] equalizer was replaced with the internal virtus/equalizer (solnic)
         | 
| 6 | 
            +
            * [changed] `Virtus::Attribute#==` was revised (see ef57af319334a1d4f3e0860acbde7c6d6f0eb8ef) (novikserg)
         | 
| 7 | 
            +
            * [fixed] Mass assignment bug fix (see #325) (novikserg)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            [Compare v1.0.5..v2.0.0](https://github.com/solnic/virtus/compare/v1.0.5...v2.0.0)
         | 
| 10 | 
            +
             | 
| 1 11 | 
             
            # v1.0.5 2015-03-18
         | 
| 2 12 |  | 
| 3 13 | 
             
            * [feature] Support for :nullify_blank option when configuring a virtus module (lucasmazza)
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -2,20 +2,9 @@ source 'https://rubygems.org' | |
| 2 2 |  | 
| 3 3 | 
             
            gemspec
         | 
| 4 4 |  | 
| 5 | 
            -
            gem ' | 
| 6 | 
            -
            gem ' | 
| 7 | 
            -
            gem ' | 
| 5 | 
            +
            gem 'dry-inflector'
         | 
| 6 | 
            +
            gem 'rspec'
         | 
| 7 | 
            +
            gem 'bogus'
         | 
| 8 | 
            +
            gem 'simplecov', platform: :ruby
         | 
| 8 9 |  | 
| 9 10 | 
             
            gem "codeclimate-test-reporter", group: :test, require: false
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            group :tools do
         | 
| 12 | 
            -
              gem 'guard'
         | 
| 13 | 
            -
              gem 'guard-rspec'
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              gem 'rubocop'
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              platform :mri do
         | 
| 18 | 
            -
                gem 'mutant'
         | 
| 19 | 
            -
                gem 'mutant-rspec'
         | 
| 20 | 
            -
              end
         | 
| 21 | 
            -
            end
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,18 +1,21 @@ | |
| 1 1 | 
             
            [gem]: https://rubygems.org/gems/virtus
         | 
| 2 2 | 
             
            [travis]: https://travis-ci.org/solnic/virtus
         | 
| 3 | 
            -
            [gemnasium]: https://gemnasium.com/solnic/virtus
         | 
| 4 3 | 
             
            [codeclimate]: https://codeclimate.com/github/solnic/virtus
         | 
| 5 4 | 
             
            [coveralls]: https://coveralls.io/r/solnic/virtus
         | 
| 6 5 | 
             
            [inchpages]: http://inch-ci.org/github/solnic/virtus/
         | 
| 7 6 |  | 
| 7 | 
            +
            DISCONTINUED
         | 
| 8 | 
            +
            ------------
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            > Working on virtus taught me a lot about handling data in Ruby, which involves coercions, type safety and validation (amongst other things). Even though the project has been successful, and serving well for many people, I decided to build something better. As a result, [dry-types](https://github.com/dry-rb/dry-types), [dry-struct](https://github.com/dry-rb/dry-struct) and [dry-schema](https://github.com/dry-rb/dry-schema) were born. These projects should be considered as virtus' successors, with better separation of concerns and better features. If you're interested in a modern take on same problems that virtus tried to solve, please check out these projects!
         | 
| 11 | 
            +
            >
         | 
| 12 | 
            +
            > @solnic
         | 
| 13 | 
            +
             | 
| 8 14 | 
             
            Virtus
         | 
| 9 15 | 
             
            ======
         | 
| 10 16 |  | 
| 11 | 
            -
            # Ruby Object Mapper
         | 
| 12 | 
            -
             | 
| 13 17 | 
             
            [][gem]
         | 
| 14 18 | 
             
            [][travis]
         | 
| 15 | 
            -
            [][gemnasium]
         | 
| 16 19 | 
             
            [][codeclimate]
         | 
| 17 20 | 
             
            [][codeclimate]
         | 
| 18 21 | 
             
            [][inchpages]
         | 
| @@ -61,7 +64,7 @@ class User | |
| 61 64 | 
             
            end
         | 
| 62 65 |  | 
| 63 66 | 
             
            user = User.new(:name => 'Piotr', :age => 31)
         | 
| 64 | 
            -
            user.attributes # => { :name => "Piotr", :age => 31 }
         | 
| 67 | 
            +
            user.attributes # => { :name => "Piotr", :age => 31, :birthday => nil }
         | 
| 65 68 |  | 
| 66 69 | 
             
            user.name # => "Piotr"
         | 
| 67 70 |  | 
| @@ -579,6 +582,13 @@ Blog.attribute_set[:posts].member_type.primitive # => Post | |
| 579 582 | 
             
            Post.attribute_set[:blog].type.primitive # => Blog
         | 
| 580 583 | 
             
            ```
         | 
| 581 584 |  | 
| 585 | 
            +
            ## Plugins / Extensions
         | 
| 586 | 
            +
             | 
| 587 | 
            +
            List of plugins/extensions that add features to Virtus:
         | 
| 588 | 
            +
             | 
| 589 | 
            +
            * [virtus-localized](https://github.com/XescuGC/virtus-localized): Localize the attributes
         | 
| 590 | 
            +
            * [virtus-relations](https://github.com/smanolloff/virtus-relations): Add relations to Virtus objects
         | 
| 591 | 
            +
             | 
| 582 592 | 
             
            Ruby version support
         | 
| 583 593 | 
             
            --------------------
         | 
| 584 594 |  | 
    
        data/lib/virtus.rb
    CHANGED
    
    | @@ -207,6 +207,25 @@ module Virtus | |
| 207 207 | 
             
                @configuration ||= Configuration.new
         | 
| 208 208 | 
             
              end
         | 
| 209 209 |  | 
| 210 | 
            +
              # @api private
         | 
| 211 | 
            +
              def self.constantize(type)
         | 
| 212 | 
            +
                inflector.constantize(type)
         | 
| 213 | 
            +
              end
         | 
| 214 | 
            +
             | 
| 215 | 
            +
              # @api private
         | 
| 216 | 
            +
              def self.inflector
         | 
| 217 | 
            +
                @inflector ||=
         | 
| 218 | 
            +
                  begin
         | 
| 219 | 
            +
                    require 'dry/inflector'
         | 
| 220 | 
            +
                    Dry::Inflector.new
         | 
| 221 | 
            +
                  rescue LoadError
         | 
| 222 | 
            +
                    raise(
         | 
| 223 | 
            +
                      NotImplementedError,
         | 
| 224 | 
            +
                      'Virtus needs dry-inflector gem to constantize namespaced constant names'
         | 
| 225 | 
            +
                    )
         | 
| 226 | 
            +
                  end
         | 
| 227 | 
            +
              end
         | 
| 228 | 
            +
             | 
| 210 229 | 
             
              # Finalize pending attributes
         | 
| 211 230 | 
             
              #
         | 
| 212 231 | 
             
              # @example
         | 
| @@ -241,7 +260,6 @@ module Virtus | |
| 241 260 | 
             
            end # module Virtus
         | 
| 242 261 |  | 
| 243 262 | 
             
            require 'descendants_tracker'
         | 
| 244 | 
            -
            require 'equalizer'
         | 
| 245 263 | 
             
            require 'axiom-types'
         | 
| 246 264 | 
             
            require 'coercible'
         | 
| 247 265 |  | 
    
        data/lib/virtus/attribute.rb
    CHANGED
    
    | @@ -13,12 +13,12 @@ module Virtus | |
| 13 13 | 
             
              #   # strict mode
         | 
| 14 14 | 
             
              #   attr = Virtus::Attribute.build(Integer, :strict => true)
         | 
| 15 15 | 
             
              #   attr.coerce('not really coercible')
         | 
| 16 | 
            -
              #   # => Virtus::CoercionError: Failed to coerce " | 
| 16 | 
            +
              #   # => Virtus::CoercionError: Failed to coerce "not really coercible" into Integer
         | 
| 17 17 | 
             
              #
         | 
| 18 18 | 
             
              class Attribute
         | 
| 19 19 | 
             
                extend DescendantsTracker, Options, TypeLookup
         | 
| 20 20 |  | 
| 21 | 
            -
                include  | 
| 21 | 
            +
                include Equalizer.new(inspect) << :type << :options
         | 
| 22 22 |  | 
| 23 23 | 
             
                accept_options :primitive, :accessor, :default, :lazy, :strict, :required, :finalize, :nullify_blank
         | 
| 24 24 |  | 
| @@ -25,13 +25,7 @@ module Virtus | |
| 25 25 | 
             
                # @api private
         | 
| 26 26 | 
             
                def determine_type
         | 
| 27 27 | 
             
                  if type.include?('::')
         | 
| 28 | 
            -
                     | 
| 29 | 
            -
                    #       pick up either Inflecto or ActiveSupport, whateve is available
         | 
| 30 | 
            -
                    if defined?(Inflecto)
         | 
| 31 | 
            -
                      Inflecto.constantize(type)
         | 
| 32 | 
            -
                    else
         | 
| 33 | 
            -
                      raise NotImplementedError, 'Virtus needs inflecto gem to constantize namespaced constant names'
         | 
| 34 | 
            -
                    end
         | 
| 28 | 
            +
                    Virtus.constantize(type)
         | 
| 35 29 | 
             
                  else
         | 
| 36 30 | 
             
                    Object.const_get(type)
         | 
| 37 31 | 
             
                  end
         | 
    
        data/lib/virtus/builder.rb
    CHANGED
    
    | @@ -120,11 +120,7 @@ module Virtus | |
| 120 120 |  | 
| 121 121 | 
             
                # @api private
         | 
| 122 122 | 
             
                def extensions
         | 
| 123 | 
            -
                  super  | 
| 124 | 
            -
                    Extensions::AllowedWriterMethods,
         | 
| 125 | 
            -
                    ValueObject::AllowedWriterMethods,
         | 
| 126 | 
            -
                    ValueObject::InstanceMethods
         | 
| 127 | 
            -
                  ]
         | 
| 123 | 
            +
                  super << ValueObject::AllowedWriterMethods << ValueObject::InstanceMethods
         | 
| 128 124 | 
             
                end
         | 
| 129 125 |  | 
| 130 126 | 
             
                # @api private
         | 
| @@ -13,7 +13,6 @@ module Virtus | |
| 13 13 | 
             
                def self.included(descendant)
         | 
| 14 14 | 
             
                  super
         | 
| 15 15 | 
             
                  descendant.extend(ClassMethods)
         | 
| 16 | 
            -
                  descendant.extend(Extensions::AllowedWriterMethods)
         | 
| 17 16 | 
             
                  descendant.class_eval { include Methods }
         | 
| 18 17 | 
             
                  descendant.class_eval { include InstanceMethods }
         | 
| 19 18 | 
             
                  descendant.class_eval { include InstanceMethods::Constructor }
         | 
    
        data/lib/virtus/coercer.rb
    CHANGED
    
    
    
        data/lib/virtus/extensions.rb
    CHANGED
    
    | @@ -18,7 +18,6 @@ module Virtus | |
| 18 18 | 
             
                  object.instance_eval do
         | 
| 19 19 | 
             
                    extend Methods
         | 
| 20 20 | 
             
                    extend InstanceMethods
         | 
| 21 | 
            -
                    extend AllowedWriterMethods
         | 
| 22 21 | 
             
                    extend InstanceMethods::MassAssignment
         | 
| 23 22 | 
             
                  end
         | 
| 24 23 | 
             
                end
         | 
| @@ -72,26 +71,9 @@ module Virtus | |
| 72 71 | 
             
                  def values(&block)
         | 
| 73 72 | 
             
                    private :attributes= if instance_methods.include?(:attributes=)
         | 
| 74 73 | 
             
                    yield
         | 
| 75 | 
            -
                    include( | 
| 74 | 
            +
                    include(Equalizer.new(name, attribute_set.map(&:name)))
         | 
| 76 75 | 
             
                  end
         | 
| 77 76 |  | 
| 78 | 
            -
                  private
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                  # Return an attribute set for that instance
         | 
| 81 | 
            -
                  #
         | 
| 82 | 
            -
                  # @return [AttributeSet]
         | 
| 83 | 
            -
                  #
         | 
| 84 | 
            -
                  # @api private
         | 
| 85 | 
            -
                  def attribute_set
         | 
| 86 | 
            -
                    @attribute_set
         | 
| 87 | 
            -
                  end
         | 
| 88 | 
            -
             | 
| 89 | 
            -
                end # Methods
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                module AllowedWriterMethods
         | 
| 92 | 
            -
                  WRITER_METHOD_REGEXP   = /=\z/.freeze
         | 
| 93 | 
            -
                  INVALID_WRITER_METHODS = %w[ == != === []= attributes= ].to_set.freeze
         | 
| 94 | 
            -
             | 
| 95 77 | 
             
                  # The list of writer methods that can be mass-assigned to in #attributes=
         | 
| 96 78 | 
             
                  #
         | 
| 97 79 | 
             
                  # @return [Set]
         | 
| @@ -106,8 +88,18 @@ module Virtus | |
| 106 88 | 
             
                      end
         | 
| 107 89 | 
             
                  end
         | 
| 108 90 |  | 
| 109 | 
            -
             | 
| 91 | 
            +
                  private
         | 
| 110 92 |  | 
| 111 | 
            -
             | 
| 93 | 
            +
                  # Return an attribute set for that instance
         | 
| 94 | 
            +
                  #
         | 
| 95 | 
            +
                  # @return [AttributeSet]
         | 
| 96 | 
            +
                  #
         | 
| 97 | 
            +
                  # @api private
         | 
| 98 | 
            +
                  def attribute_set
         | 
| 99 | 
            +
                    @attribute_set
         | 
| 100 | 
            +
                  end
         | 
| 112 101 |  | 
| 102 | 
            +
                end # Methods
         | 
| 103 | 
            +
             | 
| 104 | 
            +
              end # module Extensions
         | 
| 113 105 | 
             
            end # module Virtus
         | 
    
        data/lib/virtus/model.rb
    CHANGED
    
    | @@ -31,7 +31,7 @@ module Virtus | |
| 31 31 | 
             
                    descendant.extend(Extensions::Methods)
         | 
| 32 32 | 
             
                    descendant.extend(InstanceMethods)
         | 
| 33 33 | 
             
                  end
         | 
| 34 | 
            -
                  private_class_method : | 
| 34 | 
            +
                  private_class_method :extended
         | 
| 35 35 |  | 
| 36 36 | 
             
                end # Core
         | 
| 37 37 |  | 
| @@ -51,7 +51,6 @@ module Virtus | |
| 51 51 | 
             
                  # @api private
         | 
| 52 52 | 
             
                  def self.included(descendant)
         | 
| 53 53 | 
             
                    super
         | 
| 54 | 
            -
                    descendant.extend(Extensions::AllowedWriterMethods)
         | 
| 55 54 | 
             
                    descendant.send(:include, InstanceMethods::MassAssignment)
         | 
| 56 55 | 
             
                  end
         | 
| 57 56 | 
             
                  private_class_method :included
         | 
| @@ -59,7 +58,6 @@ module Virtus | |
| 59 58 | 
             
                  # @api private
         | 
| 60 59 | 
             
                  def self.extended(descendant)
         | 
| 61 60 | 
             
                    super
         | 
| 62 | 
            -
                    descendant.extend(Extensions::AllowedWriterMethods)
         | 
| 63 61 | 
             
                    descendant.extend(InstanceMethods::MassAssignment)
         | 
| 64 62 | 
             
                  end
         | 
| 65 63 | 
             
                  private_class_method :extended
         | 
    
        data/lib/virtus/version.rb
    CHANGED
    
    
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe "Adding attribute called 'attributes'" do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              context "when mass assignment is disabled" do
         | 
| 6 | 
            +
                before do
         | 
| 7 | 
            +
                  module Examples
         | 
| 8 | 
            +
                    class User
         | 
| 9 | 
            +
                      include Virtus.model(mass_assignment: false)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                      attribute :attributes
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                it "allows model to use `attributes` attribute" do
         | 
| 17 | 
            +
                  user = Examples::User.new
         | 
| 18 | 
            +
                  expect(user.attributes).to eq(nil)
         | 
| 19 | 
            +
                  user.attributes = "attributes string"
         | 
| 20 | 
            +
                  expect(user.attributes).to eq("attributes string")
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                it "doesn't accept `attributes` key in initializer" do
         | 
| 24 | 
            +
                  user = Examples::User.new(attributes: 'attributes string')
         | 
| 25 | 
            +
                  expect(user.attributes).to eq(nil)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,12 +1,11 @@ | |
| 1 | 
            -
            if RUBY_ENGINE ==  | 
| 2 | 
            -
              require  | 
| 3 | 
            -
               | 
| 1 | 
            +
            if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '3.0'
         | 
| 2 | 
            +
              require 'simplecov'
         | 
| 3 | 
            +
              SimpleCov.start
         | 
| 4 4 | 
             
            end
         | 
| 5 5 |  | 
| 6 6 | 
             
            require 'rspec'
         | 
| 7 7 | 
             
            require 'bogus/rspec'
         | 
| 8 8 | 
             
            require 'virtus'
         | 
| 9 | 
            -
            require 'inflecto' # for resolving namespaced constant names
         | 
| 10 9 |  | 
| 11 10 | 
             
            module Virtus
         | 
| 12 11 | 
             
              def self.warn(*)
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require 'set'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Virtus::Attribute::Collection, '#value_coerced?' do
         | 
| 5 | 
            +
              subject { object.value_coerced?(input) }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              let(:object) { described_class.build(Array[Integer]) }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              context 'when input has correctly typed members' do
         | 
| 10 | 
            +
                let(:input) { [1, 2, 3] }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                it { is_expected.to be(true) }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              context 'when input has incorrectly typed members' do
         | 
| 16 | 
            +
                let(:input) { [1, 2, '3'] }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                it { is_expected.to be(false) }
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              context 'when the collection type is incorrect' do
         | 
| 22 | 
            +
                let(:input) { Set[1, 2, 3] }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                it { is_expected.to be(false) }
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              context 'when the input is empty' do
         | 
| 28 | 
            +
                let(:input) { [] }
         | 
| 29 | 
            +
                it { is_expected.to be(true) }
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Virtus::Attribute, '#== (defined by including Virtus::Equalizer)' do
         | 
| 4 | 
            +
              let(:attribute) { described_class.build(String, :name => :name) }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              it 'returns true when attributes have same type and options' do
         | 
| 7 | 
            +
                equal_attribute = described_class.build(String, :name => :name)
         | 
| 8 | 
            +
                expect(attribute == equal_attribute).to be_truthy
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              it 'returns false when attributes have different type' do
         | 
| 12 | 
            +
                different_attribute = described_class.build(Integer, :name => :name)
         | 
| 13 | 
            +
                expect(attribute == different_attribute).to be_falsey
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              it 'returns false when attributes have different options' do
         | 
| 17 | 
            +
                different_attribute = described_class.build(Integer, :name => :name_two)
         | 
| 18 | 
            +
                expect(attribute == different_attribute).to be_falsey
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -38,10 +38,10 @@ describe Virtus::AttributeSet, '#<<' do | |
| 38 38 |  | 
| 39 39 | 
             
                it { is_expected.to equal(object) }
         | 
| 40 40 |  | 
| 41 | 
            -
                it  | 
| 42 | 
            -
                  expect { subject }.to change { object.to_a }.
         | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 41 | 
            +
                it "replaces the original attribute object" do
         | 
| 42 | 
            +
                  expect { subject }.to change { object.to_a.map(&:__id__) }.
         | 
| 43 | 
            +
                  from(attributes.map(&:__id__)).
         | 
| 44 | 
            +
                  to([attribute.__id__])
         | 
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
              end
         | 
| 47 47 | 
             
            end
         | 
| @@ -37,20 +37,28 @@ describe Virtus::AttributeSet, '#[]=' do | |
| 37 37 |  | 
| 38 38 | 
             
                it { is_expected.to equal(attribute) }
         | 
| 39 39 |  | 
| 40 | 
            -
                it  | 
| 41 | 
            -
                  expect { subject }.to change { object.to_a | 
| 40 | 
            +
                it "replaces the original attribute object" do
         | 
| 41 | 
            +
                  expect { subject }.to change { object.to_a.map(&:__id__) }.
         | 
| 42 | 
            +
                  from(attributes.map(&:__id__)).
         | 
| 43 | 
            +
                  to([attribute.__id__])
         | 
| 42 44 | 
             
                end
         | 
| 43 45 |  | 
| 44 | 
            -
                it 'allows #[] to access the attribute with a  | 
| 45 | 
            -
                  expect { subject }.to change { object['name'] }. | 
| 46 | 
            +
                it 'allows #[] to access the attribute with a string' do
         | 
| 47 | 
            +
                  expect { subject }.to change { object['name'].__id__ }.
         | 
| 48 | 
            +
                  from(original.__id__).
         | 
| 49 | 
            +
                  to(attribute.__id__)
         | 
| 46 50 | 
             
                end
         | 
| 47 51 |  | 
| 48 | 
            -
                it 'allows #[] to access the attribute with a  | 
| 49 | 
            -
                  expect { subject }.to change { object[:name] }. | 
| 52 | 
            +
                it 'allows #[] to access the attribute with a symbol' do
         | 
| 53 | 
            +
                  expect { subject }.to change { object[:name].__id__ }.
         | 
| 54 | 
            +
                  from(original.__id__).
         | 
| 55 | 
            +
                  to(attribute.__id__)
         | 
| 50 56 | 
             
                end
         | 
| 51 57 |  | 
| 52 58 | 
             
                it 'allows #reset to track overridden attributes' do
         | 
| 53 | 
            -
                  expect { subject }.to change { object.reset.to_a | 
| 59 | 
            +
                  expect { subject }.to change { object.reset.to_a.map(&:__id__) }.
         | 
| 60 | 
            +
                  from(attributes.map(&:__id__)).
         | 
| 61 | 
            +
                  to([attribute.__id__])
         | 
| 54 62 | 
             
                end
         | 
| 55 63 | 
             
              end
         | 
| 56 64 | 
             
            end
         | 
| @@ -21,12 +21,14 @@ describe Virtus::AttributeSet, '#merge' do | |
| 21 21 |  | 
| 22 22 | 
             
              context 'with a duplicate attribute' do
         | 
| 23 23 | 
             
                let(:attributes) { [Virtus::Attribute.build(String, :name => name)] }
         | 
| 24 | 
            -
                let(:attribute)  { | 
| 24 | 
            +
                let(:attribute)  {  Virtus::Attribute.build(String, :name => name) }
         | 
| 25 25 |  | 
| 26 26 | 
             
                it { is_expected.to equal(object) }
         | 
| 27 27 |  | 
| 28 | 
            -
                it  | 
| 29 | 
            -
                  expect { subject }.to change { object.to_a | 
| 28 | 
            +
                it "replaces the original attribute object" do
         | 
| 29 | 
            +
                  expect { subject }.to change { object.to_a.map(&:__id__) }.
         | 
| 30 | 
            +
                  from(attributes.map(&:__id__)).
         | 
| 31 | 
            +
                  to([attribute.__id__])
         | 
| 30 32 | 
             
                end
         | 
| 31 33 | 
             
              end
         | 
| 32 34 | 
             
            end
         | 
    
        data/virtus.gemspec
    CHANGED
    
    | @@ -18,9 +18,9 @@ Gem::Specification.new do |gem| | |
| 18 18 | 
             
              gem.extra_rdoc_files = %w[LICENSE README.md TODO.md]
         | 
| 19 19 |  | 
| 20 20 | 
             
              gem.add_dependency('descendants_tracker', '~> 0.0', '>= 0.0.3')
         | 
| 21 | 
            -
              gem.add_dependency('equalizer', '~> 0.0', '>= 0.0.9')
         | 
| 22 21 | 
             
              gem.add_dependency('coercible', '~> 1.0')
         | 
| 23 22 | 
             
              gem.add_dependency('axiom-types', '~> 0.1')
         | 
| 24 23 |  | 
| 25 24 | 
             
              gem.add_development_dependency 'rake'
         | 
| 25 | 
            +
              gem.required_ruby_version = '>= 2.0'
         | 
| 26 26 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: virtus
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Piotr Solnica
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-06-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: descendants_tracker
         | 
| @@ -30,26 +30,6 @@ dependencies: | |
| 30 30 | 
             
                - - ">="
         | 
| 31 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 32 | 
             
                    version: 0.0.3
         | 
| 33 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 34 | 
            -
              name: equalizer
         | 
| 35 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 36 | 
            -
                requirements:
         | 
| 37 | 
            -
                - - "~>"
         | 
| 38 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            -
                    version: '0.0'
         | 
| 40 | 
            -
                - - ">="
         | 
| 41 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 42 | 
            -
                    version: 0.0.9
         | 
| 43 | 
            -
              type: :runtime
         | 
| 44 | 
            -
              prerelease: false
         | 
| 45 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 46 | 
            -
                requirements:
         | 
| 47 | 
            -
                - - "~>"
         | 
| 48 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            -
                    version: '0.0'
         | 
| 50 | 
            -
                - - ">="
         | 
| 51 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            -
                    version: 0.0.9
         | 
| 53 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 54 34 | 
             
              name: coercible
         | 
| 55 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -106,7 +86,6 @@ files: | |
| 106 86 | 
             
            - ".pelusa.yml"
         | 
| 107 87 | 
             
            - ".rspec"
         | 
| 108 88 | 
             
            - ".ruby-gemset"
         | 
| 109 | 
            -
            - ".ruby-version"
         | 
| 110 89 | 
             
            - ".travis.yml"
         | 
| 111 90 | 
             
            - ".yardopts"
         | 
| 112 91 | 
             
            - CONTRIBUTING.md
         | 
| @@ -151,6 +130,7 @@ files: | |
| 151 130 | 
             
            - lib/virtus/support/type_lookup.rb
         | 
| 152 131 | 
             
            - lib/virtus/value_object.rb
         | 
| 153 132 | 
             
            - lib/virtus/version.rb
         | 
| 133 | 
            +
            - spec/integration/attributes_attribute_spec.rb
         | 
| 154 134 | 
             
            - spec/integration/building_module_spec.rb
         | 
| 155 135 | 
             
            - spec/integration/collection_member_coercion_spec.rb
         | 
| 156 136 | 
             
            - spec/integration/custom_attributes_spec.rb
         | 
| @@ -183,6 +163,8 @@ files: | |
| 183 163 | 
             
            - spec/unit/virtus/attribute/coercible_predicate_spec.rb
         | 
| 184 164 | 
             
            - spec/unit/virtus/attribute/collection/class_methods/build_spec.rb
         | 
| 185 165 | 
             
            - spec/unit/virtus/attribute/collection/coerce_spec.rb
         | 
| 166 | 
            +
            - spec/unit/virtus/attribute/collection/value_coerced_predicate_spec.rb
         | 
| 167 | 
            +
            - spec/unit/virtus/attribute/comparison_spec.rb
         | 
| 186 168 | 
             
            - spec/unit/virtus/attribute/custom_collection_spec.rb
         | 
| 187 169 | 
             
            - spec/unit/virtus/attribute/defined_spec.rb
         | 
| 188 170 | 
             
            - spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
         | 
| @@ -222,7 +204,7 @@ homepage: https://github.com/solnic/virtus | |
| 222 204 | 
             
            licenses:
         | 
| 223 205 | 
             
            - MIT
         | 
| 224 206 | 
             
            metadata: {}
         | 
| 225 | 
            -
            post_install_message: | 
| 207 | 
            +
            post_install_message:
         | 
| 226 208 | 
             
            rdoc_options: []
         | 
| 227 209 | 
             
            require_paths:
         | 
| 228 210 | 
             
            - lib
         | 
| @@ -230,16 +212,15 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 230 212 | 
             
              requirements:
         | 
| 231 213 | 
             
              - - ">="
         | 
| 232 214 | 
             
                - !ruby/object:Gem::Version
         | 
| 233 | 
            -
                  version: '0'
         | 
| 215 | 
            +
                  version: '2.0'
         | 
| 234 216 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 235 217 | 
             
              requirements:
         | 
| 236 218 | 
             
              - - ">="
         | 
| 237 219 | 
             
                - !ruby/object:Gem::Version
         | 
| 238 220 | 
             
                  version: '0'
         | 
| 239 221 | 
             
            requirements: []
         | 
| 240 | 
            -
             | 
| 241 | 
            -
             | 
| 242 | 
            -
            signing_key: 
         | 
| 222 | 
            +
            rubygems_version: 3.2.15
         | 
| 223 | 
            +
            signing_key:
         | 
| 243 224 | 
             
            specification_version: 4
         | 
| 244 225 | 
             
            summary: Attributes on Steroids for Plain Old Ruby Objects
         | 
| 245 226 | 
             
            test_files: []
         | 
    
        data/.ruby-version
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            2.1
         |