Skip to content

Instantly share code, notes, and snippets.

@liangzan
Created September 11, 2010 03:08
Show Gist options
  • Save liangzan/574730 to your computer and use it in GitHub Desktop.
Save liangzan/574730 to your computer and use it in GitHub Desktop.
# lib/validation_reflection.rb
def install(base)
@@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
def #{validation_type}_with_reflection(*attr_names)
ignoring_subvalidations(#{ignore_subvalidations}) do
#{validation_type}_without_reflection(*attr_names)
remember_validation_metadata(:#{validation_type}, *attr_names)
end
end
alias_method_chain :#{validation_type}, :reflection
end
}, __FILE__, __LINE__
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment