Module: GLiveValidator::ActiveRecordExtensions::ValidationReflection
- Defined in:
- lib/g_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/g_live_validator/active_record_extensions.rb', line 31 def self.included( base ) base.extend( ClassMethods ) for validation_type in VALIDATIONS base.module_eval <<-"end_eval" class << self alias_method :#{validation_type}_without_reflection, :#{validation_type} def #{validation_type}_with_reflection(*attr_names) #{validation_type}_without_reflection(*attr_names) configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : nil for attr_name in attr_names write_inheritable_array "validations", [ ActiveRecord::Reflection::MacroReflection.new(:#{validation_type}, attr_name, configuration, self) ] end end alias_method :#{validation_type}, :#{validation_type}_with_reflection end end_eval end end |