Class: DataMapper::Validations::MethodValidator

Inherits:
GenericValidator show all
Defined in:
lib/dm-validations/validators/method_validator.rb

Overview

Author:

  • Guy van den Berg

Since:

  • 0.9

Instance Attribute Summary

Attributes inherited from GenericValidator

#field_name, #humanized_field_name, #if_clause, #options, #unless_clause

Instance Method Summary collapse

Methods inherited from GenericValidator

#add_error, #evaluate_conditional_clause, #execute?, #inspect, #optional?, #set_optional_by_default

Constructor Details

#initialize(field_name, options = {}) ⇒ MethodValidator

Returns a new instance of MethodValidator.

Since:

  • 0.9



7
8
9
10
# File 'lib/dm-validations/validators/method_validator.rb', line 7

def initialize(field_name, options={})
  super
  @options[:method] = @field_name unless @options.key?(:method)
end

Instance Method Details

#==(other) ⇒ Object

Since:

  • 0.9



18
19
20
# File 'lib/dm-validations/validators/method_validator.rb', line 18

def ==(other)
  @options[:method] == other.instance_variable_get(:@options)[:method] && super
end

#call(target) ⇒ Object

Since:

  • 0.9



12
13
14
15
16
# File 'lib/dm-validations/validators/method_validator.rb', line 12

def call(target)
  result, message = target.__send__(@options[:method])
  add_error(target, message, field_name) unless result
  result
end