Class: AWS::Record::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/record/validator.rb

Overview

Base class for all validators

Constant Summary collapse

ACCEPTED_OPTIONS =

these should be defined in subclasses

[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_class, *attribute_names, &block) ⇒ Validator

Returns a new instance of Validator.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aws/record/validator.rb', line 24

def initialize record_class, *attribute_names, &block

  @options = attribute_names.last.is_a?(Hash) ? attribute_names.pop : {}

  @attribute_names = attribute_names

  reject_unknown_options

  ensure_type([Symbol, Proc], :if, :unless)
  ensure_is([:save, :create, :update], :on) 

  setup(record_class)

end

Instance Attribute Details

#attribute_namesString (readonly)

Returns the name of the attribute this validator will check on the record during validation.

Returns:

  • (String)

    Returns the name of the attribute this validator will check on the record during validation.



41
42
43
# File 'lib/aws/record/validator.rb', line 41

def attribute_names
  @attribute_names
end

#optionsHash (readonly)

Returns the hash of options for this validator.

Returns:

  • (Hash)

    Returns the hash of options for this validator.



44
45
46
# File 'lib/aws/record/validator.rb', line 44

def options
  @options
end

Instance Method Details

#validate(record) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/aws/record/validator.rb', line 46

def validate record
  if 
    passes_on_condition?(record) and
    passes_if_condition?(record) and
    passes_unless_condition?(record)
  then
    validate_attributes(record)
  end
end