Sha256: 968e0b8de2cc089df80b0de3f6526efabdafff35a02e643f1d84841c01b3decc

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

module Shoulda
  module Matchers
    module ActiveModel
      class AllowValueMatcher
        # @private
        class AttributeSettersAndValidators
          include Enumerable

          def initialize(allow_value_matcher, values)
            @tuples = values.map do |attribute_name, value|
              AttributeSetterAndValidator.new(
                allow_value_matcher,
                attribute_name,
                value
              )
            end
          end

          def each(&block)
            tuples.each(&block)
          end

          def first_passing
            tuples.detect(&method(:matches?))
          end

          def first_failing
            tuples.detect(&method(:does_not_match?))
          end

          protected

          attr_reader :tuples

          private

          def matches?(tuple)
            tuple.attribute_setter.set! && tuple.validator.call
          end

          def does_not_match?(tuple)
            !matches?(tuple)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shoulda-matchers-4.4.1 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.4.0 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.3.0 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.2.0 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.1.2 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.1.1 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.1.0 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.0.1 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-3.1.3 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-4.0.0.rc1 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-3.1.2 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-3.1.1 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb
shoulda-matchers-3.1.0 lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb