Skip to content

Instantly share code, notes, and snippets.

@jschairb
Created May 30, 2013 03:49
Show Gist options
  • Save jschairb/5675618 to your computer and use it in GitHub Desktop.
Save jschairb/5675618 to your computer and use it in GitHub Desktop.
playing around with de-coupling data from logic in ORM-based objects
class Persistence::Mongoid::Operation
include Mongoid::Document
end
class Persistence::Memory::Operation
end
module Persistence
def self.included(klass)
klass.send(:include, InstanceMethods)
end
class InstanceMethods
end
end
class Operation
WRITABLE_ATTRIBUTES = [:status, :type]
attr_accessor *WRITABLE_ATTRIBUTES
include Persistence
def initialize(attributes, persistence)
end
def record
@record ||= persistence.find(identifier)
end
def save
@record.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment