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, &block) ⇒ EachValidator

Returns a new instance of EachValidator.



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

def initialize(klass, &block)
  @source_class = klass
  @source_class.class_eval(&block)
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

#validateObject



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

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