Permalink
Browse files

doc update

custom validation variable name change
  • Loading branch information...
1 parent 04b251b commit ae664f5e9850aae8a7d21bcf0434e1d2581701ff @redinger committed Jun 13, 2010
Showing with 5 additions and 8 deletions.
  1. +2 −2 README
  2. +3 −6 lib/validation_reflection.rb
View
4 README
@@ -31,9 +31,9 @@ ActiveRecord::Reflection::MacroReflection. For example
Usually, all the standard Rails validations are reflected.
You can change this -- add or remove validations -- in an
-application-specific configuration file,
+application-specific initializer,
- config/plugins/validation_reflection.rb
+ config/initializers/validation_reflection.rb
In that file change config.reflected_validations to suit your
needs. Say, you have a custom validation for email addresses,
@@ -1,9 +1,5 @@
-require 'active_record/reflection'
require 'ostruct'
-# Based on code by Sebastian Kanthak
-# See http://dev.rubyonrails.org/ticket/861
-#
module ValidationReflection # :nodoc:
extend self
@@ -22,6 +18,7 @@ module ValidationReflection # :nodoc:
].freeze
@@reflected_validations = CORE_VALIDATONS.dup
+
@@in_ignored_subvalidation = false
mattr_accessor :reflected_validations,
@@ -66,7 +63,7 @@ module ClassMethods
# Returns an array of MacroReflection objects for all validations in the class
def reflect_on_all_validations
- self.read_inheritable_attribute(:validations) || []
+ self.read_inheritable_attribute(:reflected_validations) || []
end
# Returns an array of MacroReflection objects for all validations defined for the field +attr_name+.
@@ -83,7 +80,7 @@ def reflect_on_validations_for(attr_name)
def remember_validation_metadata(validation_type, *attr_names)
configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
attr_names.flatten.each do |attr_name|
- self.write_inheritable_array :validations,
+ self.write_inheritable_array :reflected_validations,
[::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
end
end

0 comments on commit ae664f5

Please sign in to comment.