Created
September 2, 2010 23:40
-
-
Save bowsersenior/563153 to your computer and use it in GitHub Desktop.
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
module Workflow | |
module MongoidInstanceMethods | |
def load_workflow_state | |
self.workflow_state | |
end | |
def persist_workflow_state(new_value) | |
self.workflow_state = new_value | |
save! | |
end | |
end | |
def self.included(klass) | |
klass.send :include, WorkflowInstanceMethods | |
klass.extend WorkflowClassMethods | |
if Object.const_defined?(:ActiveRecord) && klass < ActiveRecord::Base | |
klass.send :include, ActiveRecordInstanceMethods | |
klass.before_validation :write_initial_state | |
elsif Object.const_defined?(:Remodel) && klass < Remodel::Entity | |
klass.send :include, RemodelInstanceMethods | |
elsif Object.const_defined?(:Mongoid) && klass < Mongoid::Document | |
klass.send :field, :workflow_state | |
klass.send :include, MongoidInstanceMethods | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment