Module: ActiveScaffold::ValidationReflectionBridge

Defined in:
lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb', line 3

def self.included(base)
  base.class_eval { alias_method_chain :initialize, :validation_reflection }
end

Instance Method Details

#initialize_with_validation_reflection(name, active_record_class) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb', line 7

def initialize_with_validation_reflection(name, active_record_class)
  initialize_without_validation_reflection(name, active_record_class)
  column_names = [name]
  column_names << @association.primary_key_name if @association
  self.required = column_names.any? do |column_name|
    active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val|
      val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank])
    end
  end
end