Class: DataMapper::Validations::MethodValidator
- Inherits:
-
GenericValidator
- Object
- GenericValidator
- DataMapper::Validations::MethodValidator
- Defined in:
- lib/dm-validations/validators/method_validator.rb
Overview
Instance Attribute Summary
Attributes inherited from GenericValidator
#field_name, #humanized_field_name, #if_clause, #options, #unless_clause
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(target) ⇒ Object
-
#initialize(field_name, options = {}) ⇒ MethodValidator
constructor
A new instance of MethodValidator.
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.
7 8 9 10 |
# File 'lib/dm-validations/validators/method_validator.rb', line 7 def initialize(field_name, ={}) super @options[:method] = @field_name unless @options.key?(:method) end |
Instance Method Details
#==(other) ⇒ Object
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
12 13 14 15 16 |
# File 'lib/dm-validations/validators/method_validator.rb', line 12 def call(target) result, = target.__send__(@options[:method]) add_error(target, , field_name) unless result result end |