Module: LiveValidator::ActiveRecordExtensions::ValidationReflection

Defined in:
lib/live_validator/active_record_extensions.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VALIDATIONS =
%w(
   validates_acceptance_of
   validates_associated
   validates_confirmation_of
   validates_exclusion_of
   validates_format_of
   validates_inclusion_of
   validates_length_of
   validates_size_of
   validates_numericality_of
   validates_presence_of
   validates_uniqueness_of
).freeze

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/live_validator/active_record_extensions.rb', line 31

def self.included( base )
  base.extend( ClassMethods )

  for validation_type in VALIDATIONS
    base.module_eval "      class << self\n        alias_method :\#{validation_type}_without_reflection, :\#{validation_type}\n\n        def \#{validation_type}_with_reflection(*attr_names)\n          \#{validation_type}_without_reflection(*attr_names)\n          configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : nil\n          for attr_name in attr_names\n            write_inheritable_array \"validations\", [ ActiveRecord::Reflection::MacroReflection.new(:\#{validation_type}, attr_name, configuration, self) ]\n          end\n        end\n\n        alias_method :\#{validation_type}, :\#{validation_type}_with_reflection\n      end\n    end_eval\n  end\nend\n"