Skip to content

Instantly share code, notes, and snippets.

@lucasmncastro
Created April 1, 2010 15:39
Show Gist options
  • Select an option

  • Save lucasmncastro/351956 to your computer and use it in GitHub Desktop.

Select an option

Save lucasmncastro/351956 to your computer and use it in GitHub Desktop.
module RequiredAttributes
def self.included(base)
base.class_eval do
class << self
@@required_attributes = []
def required?(attribute)
@@required_attributes.include? attribute
end
def validates_presence_of_with_reader(*attr_names)
validates_presence_of_without_reader(*attr_names)
attr_names.extract_options!
@@required_attributes += attr_names
end
alias_method_chain :validates_presence_of, :reader
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment