Class: DataMapper::Validate::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, #execute?, #inspect

Constructor Details

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

Returns a new instance of MethodValidator.

Since:

  • 0.9



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

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

Instance Method Details

#==(other) ⇒ Object

Since:

  • 0.9



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

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

#call(target) ⇒ Object

Since:

  • 0.9



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

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