Class: CouchRest::Validation::AbsentFieldValidator

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

Overview

Author:

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

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



32
33
34
35
# File 'lib/couchrest/validation/validators/absent_field_validator.rb', line 32

def initialize(field_name, options={})
  super
  @field_name, @options = field_name, options
end

Instance Method Details

- (Object) call(target)



37
38
39
40
41
42
43
44
45
# File 'lib/couchrest/validation/validators/absent_field_validator.rb', line 37

def call(target)
  value = target.send(field_name)
  return true if (value.nil? || (value.respond_to?(:empty?) && value.empty?))

  error_message = @options[:message] || ValidationErrors.default_error_message(:absent, field_name)
  add_error(target, error_message, field_name)

  return false
end