Last active
December 16, 2015 19:30
-
-
Save joegaudet/5485828 to your computer and use it in GitHub Desktop.
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 Learndot | |
class BaseRecord | |
include ActiveModel::Validations | |
include ActiveModel::Serialization | |
attr_accessor :attributes | |
def initialize(attributes = {}) | |
@attributes = attributes | |
end | |
def read_attribute_for_validation(key) | |
@attributes[key] | |
end | |
def self.unicorn_attr(*args) | |
args.each do |arg| | |
class << self | |
define_method(arg) do | |
@attributes[arg] | |
end | |
define_method("#{arg}=") do |value| | |
@attributes[arg] = value | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment