Created
May 30, 2013 03:49
-
-
Save jschairb/5675618 to your computer and use it in GitHub Desktop.
playing around with de-coupling data from logic in ORM-based objects
This file contains 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
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