Skip to content

Instantly share code, notes, and snippets.

@dissolved
Created February 4, 2012 04:34
Show Gist options
  • Save dissolved/1735364 to your computer and use it in GitHub Desktop.
Save dissolved/1735364 to your computer and use it in GitHub Desktop.
Alternative to Fig Leaf
class Post
delegate :errors, :valid?, :save, :to => @record
@@persistance = Class.new(ActiveRecord::Base) do
set_table_name 'posts'
def self.name
'PostRecord'
end
end
def self.most_recent(limit=10)
@@persistence.all(order: "pubdate DESC", limit: limit)
end
def self.find(id)
Post.new(@@persistence.find(id))
end
def initialize(object_or_hash = {})
@record = object_or_hash === @@persistence ? object_or_hash : @@persistence.new(object_or_hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment