Module: ActiveLayer::Validations::Validator::InstanceMethods

Defined in:
lib/active_layer/validations/validator.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject

adapter methods



33
34
35
# File 'lib/active_layer/validations/validator.rb', line 33

def attributes
  _validator && _validator.respond_to?(:attributes) ? _validator.attributes : []
end

#errorsObject



37
38
39
40
41
42
43
# File 'lib/active_layer/validations/validator.rb', line 37

def errors
  if _validator
    @errors ||= ActiveModel::Errors.new(self)
  else
    super
  end
end

#initialize(*args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_layer/validations/validator.rb', line 14

def initialize(*args, &block)
  if args.first.is_a?(Hash)
    options = args.first
    if options.has_key?(:attributes)
      self._validator = EachValidator.new(options)
    else
      self._validator = ObjectValidator.new(options)
    end
    _validator.active_layer_validator = self
  end
  super 
end

#setup(record) ⇒ Object

adapter methods



28
29
30
# File 'lib/active_layer/validations/validator.rb', line 28

def setup(record)
  # nothing to do...
end

#validate(*args, &block) ⇒ Object

This method is called in two contexts, as part of the validation callbacks when it’s setup as an adapter and to register a standard callback



48
49
50
51
52
53
54
55
# File 'lib/active_layer/validations/validator.rb', line 48

def validate(*args, &block)
  # puts "calling validate on #{self.class.name}"
  if _validator
    _validator.validate(*args, &block)
  else
    super
  end
end