Module: ActiveRecordExtensions::ValidationReflection

Defined in:
lib/validation_reflection.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

CONFIG_PATH =

:nodoc:

File.join(RAILS_ROOT, 'config', 'plugins', 'validation_reflection.rb')

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



51
52
53
54
# File 'lib/validation_reflection.rb', line 51

def self.included(base)
  return if base.kind_of?(ActiveRecordExtensions::ValidationReflection::ClassMethods)
  base.extend(ClassMethods)
end

.install(base) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/validation_reflection.rb', line 66

def self.install(base)
  reflected_validations.freeze
  reflected_validations.each do |validation_type|
    next if base.respond_to?("#{validation_type}_with_reflection")
    ignore_subvalidations = false
    if validation_type.kind_of?(Hash)
      ignore_subvalidations = validation_type[:ignore_subvalidations]
      validation_type = validation_type[:method]
    end
    base.class_eval "      class << self\n        def \#{validation_type}_with_reflection(*attr_names)\n          ignoring_subvalidations(\#{ignore_subvalidations}) do\n            \#{validation_type}_without_reflection(*attr_names)\n            remember_validation_metadata(:\#{validation_type}, *attr_names)\n          end\n        end\n\n        alias_method_chain :\#{validation_type}, :reflection\n      end\n    end_eval\n  end\nend\n"

.load_configObject



56
57
58
59
60
61
62
63
64
# File 'lib/validation_reflection.rb', line 56

def self.load_config
  if File.file?(CONFIG_PATH)
    config = OpenStruct.new
    config.reflected_validations = reflected_validations
    silence_warnings do
      eval(IO.read(CONFIG_PATH), binding, CONFIG_PATH)
    end
  end
end