Sha256: 2014c6763fbdb6655052c330ee124143f145c1147390427cfdab716c992ca943

Contents?: true

Size: 783 Bytes

Versions: 5

Compression:

Stored size: 783 Bytes

Contents

module DataMapper
  module Validations
    
    # All Validators should inherit from the GenericValidator.
    class GenericValidator
    
      # Adds an error message to the target class.
      def add_error(target, message, attribute = :base)
        target.errors.add(attribute, message)
      end
      
      # Gets the proper error message
      def validation_error_message(default, custom_message, validation_binding)
        eval("\"#{(custom_message || default)}\"", validation_binding)
      end
      
      # Call the validator. We use "call" so the operation
      # is BoundMethod and Block compatible.
      # The result should always be TRUE or FALSE.
      def call(target)
        raise 'You must overwrite this method'
      end
      
    end
        
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datamapper-0.1.0 lib/data_mapper/validations/generic_validator.rb
datamapper-0.1.1 lib/data_mapper/validations/generic_validator.rb
datamapper-0.2.0 lib/data_mapper/validations/generic_validator.rb
datamapper-0.2.1 lib/data_mapper/validations/generic_validator.rb
datamapper-0.2.2 lib/data_mapper/validations/generic_validator.rb