Skip to content

Instantly share code, notes, and snippets.

@liangzan
Created September 11, 2010 03:09
Show Gist options
  • Save liangzan/574735 to your computer and use it in GitHub Desktop.
Save liangzan/574735 to your computer and use it in GitHub Desktop.
# lib/validation_reflection.rb
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,
[::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment