Last active
December 27, 2015 02:29
-
-
Save reedlaw/7253033 to your computer and use it in GitHub Desktop.
Entity model for entities to inherit
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
class Entity | |
include ActiveModel::Validations | |
attr_accessor :id | |
def self.attr_accessor(*vars) | |
@class_attributes ||= [:id] | |
@class_attributes.concat vars | |
super(*vars) | |
end | |
def self.class_attributes | |
@class_attributes | |
end | |
def self.inherited(sublass) | |
sublass.attr_accessor(*@class_attributes) | |
end | |
def initialize(attr = {}) | |
attr.each do |name, value| | |
send("#{name}=", value) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment