Class: DataMapper::Validate::MethodValidator

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

Overview

Author:

  • Guy van den Berg

Since:

  • 0.9

Instance Attribute Summary

Attributes inherited from GenericValidator

#if_clause, #unless_clause

Instance Method Summary collapse

Methods inherited from GenericValidator

#add_error, #execute?, #field_name

Constructor Details

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

Returns a new instance of MethodValidator.

Since:

  • 0.9



10
11
12
13
14
# File 'lib/dm-validations/method_validator.rb', line 10

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

Instance Method Details

#==(other) ⇒ Object

Since:

  • 0.9



22
23
24
# File 'lib/dm-validations/method_validator.rb', line 22

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

#call(target) ⇒ Object

Since:

  • 0.9



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

def call(target)
  result,message = target.send(@options[:method])
  add_error(target,message,@field_name) if !result
  result
end