Last active
December 22, 2015 11:39
-
-
Save tubbo/6467218 to your computer and use it in GitHub Desktop.
A means of enforcing attributes on a given class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Requirable | |
def self.included(base) | |
required_attributes.each do |key,val| | |
raise NoMethodError, "'#{key}' is not defined on #{self.inspect}" | |
end | |
end | |
cattr_accessor :required_attributes | |
def self.attr_required(*attributes) | |
self.required_attributes = attributes | |
end | |
end | |
class Model | |
include Requirable | |
attr_required :name, :description | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment