Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Last active December 16, 2015 19:30
Show Gist options
  • Save joegaudet/5485828 to your computer and use it in GitHub Desktop.
Save joegaudet/5485828 to your computer and use it in GitHub Desktop.
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