Class: Cavalry::Validator::EachValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cavalry/validator/each_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ EachValidator

Returns a new instance of EachValidator.



6
7
8
# File 'lib/cavalry/validator/each_validator.rb', line 6

def initialize(klass)
  @source_class = klass
end

Instance Attribute Details

#source_classObject (readonly)

Returns the value of attribute source_class.



4
5
6
# File 'lib/cavalry/validator/each_validator.rb', line 4

def source_class
  @source_class
end

Instance Method Details

#append(&block) ⇒ Object



10
11
12
# File 'lib/cavalry/validator/each_validator.rb', line 10

def append(&block)
  @source_class.class_eval(&block)
end

#validateObject



14
15
16
17
# File 'lib/cavalry/validator/each_validator.rb', line 14

def validate
  install_force_check_belongs_to_association if Cavalry.config.force_check_belongs_to_association && @source_class.respond_to?(:reflections)
  source_class.all.flat_map {|record| validate_record(record) }.compact
end