Sha256: fe755c5ddd93607de2bab5e8ac10178d7ad651596155d6daf8cb3f3024cdc69b

Contents?: true

Size: 821 Bytes

Versions: 14

Compression:

Stored size: 821 Bytes

Contents

module Mongoa
  module MongoMapper
    module Matchers
      class ValidateBase
        attr_reader :attribute
  
        def initialize(attribute)
          @attribute = attribute
        end

        def matches?(subject)
          @subject = subject
          @validation = find_validation
        end

        def validation_type
          raise "Redefine in the subclass"
        end
        
        private

        def model_class
          @subject.class
        end
        
        def find_validation
          attr_validations = model_class.validations.select { |validation| validation.attribute == attribute }
          return nil unless attr_validations
          validation = attr_validations.detect { |validation| validation.key.include?(validation_type) }
        end        
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongoa-0.2.3 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.2.2 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.2.1 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.17 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.16 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.15 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.14 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.13 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.12 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.11 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.10 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.9 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.8 lib/mongoa/mongo_mapper/validations/validate_base.rb
mongoa-0.1.7 lib/mongoa/mongo_mapper/validations/validate_base.rb