Skip to content

Instantly share code, notes, and snippets.

@jnstq
Created September 10, 2009 21:30
Show Gist options
  • Save jnstq/184841 to your computer and use it in GitHub Desktop.
Save jnstq/184841 to your computer and use it in GitHub Desktop.
require 'activerecord'
require 'active_record/base'
require 'active_record/validations'
module ActionDuck
def self.included(klass)
klass.extend ClassMethods
klass.send(:include, InstanceMethods)
end
module ClassMethods
def self_and_descendants_from_active_record
[self]
end
def human_name
self.name.humanize
end
def human_attribute_name(attribute_key_name, options = {})
attribute_key_name.to_s.humanize
end
end
module InstanceMethods
attr_accessor :errors
def initialize(h={})
h ||= {}
h.each { |k,v| send("#{k}=", v) }
self.errors = ActiveRecord::Errors.new(self)
end
# These make an instance quack like an AR::Base
def new_record?
true
end
def id
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment