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(method_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(method_name, options={})
  super
  @method_name, @options = method_name, options
  @options[:integer_only] = false unless @options.has_key?(:integer_only)
end

Instance Method Details

#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(@method_name)
  add_error(target,message,@method_name) if !result
  result
end