Sha256: bcb795f82e941d35bdfb8c1d878a84241b6c53c1c82bfd1d1690f179ce2e7a5e

Contents?: true

Size: 869 Bytes

Versions: 41

Compression:

Stored size: 869 Bytes

Contents

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

    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
  end
end
ActiveScaffold::DataStructures::Column.class_eval do
  include ActiveScaffold::ValidationReflectionBridge
end

Version data entries

41 entries across 41 versions & 4 rubygems

Version Path
active_scaffold-3.0.0 lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb