Skip to content

Instantly share code, notes, and snippets.

@reedlaw
Last active December 27, 2015 02:29
Show Gist options
  • Save reedlaw/7253033 to your computer and use it in GitHub Desktop.
Save reedlaw/7253033 to your computer and use it in GitHub Desktop.
Entity model for entities to inherit
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