Created
September 10, 2009 21:30
-
-
Save jnstq/184841 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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