Class: CouchRest::Validation::MethodValidator

Inherits:
GenericValidator show all
Defined in:
lib/couchrest/validation/validators/method_validator.rb

Overview

Author:

Since:

Instance Attribute Summary

Attributes inherited from GenericValidator

#field_name, #if_clause, #unless_clause

Instance Method Summary (collapse)

Methods inherited from GenericValidator

#add_error, #execute?

Constructor Details

- (MethodValidator) initialize(field_name, options = {})

Returns a new instance of MethodValidator

Since:

  • 0.9



33
34
35
36
37
# File 'lib/couchrest/validation/validators/method_validator.rb', line 33

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

- (Object) ==(other)

Since:

  • 0.9



45
46
47
# File 'lib/couchrest/validation/validators/method_validator.rb', line 45

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

- (Object) call(target)

Since:

  • 0.9



39
40
41
42
43
# File 'lib/couchrest/validation/validators/method_validator.rb', line 39

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