Sha256: e2f5ce75e1ab196123edc50cae33abdcaee8f3fa3ff07357bf50aee700c8106c
Contents?: true
Size: 1.04 KB
Versions: 4
Compression:
Stored size: 1.04 KB
Contents
require 'workflow' module Workflow module MongoidInstanceMethods def load_workflow_state send(self.class.workflow_column) end def persist_workflow_state(new_value) self.update_attribute(self.class.workflow_column, new_value) end private def write_initial_state send("#{self.class.workflow_column}=", current_state.to_s) if load_workflow_state.blank? 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.class_eval do klass.send :include, MongoidInstanceMethods klass.before_validation :write_initial_state end end end end
Version data entries
4 entries across 4 versions & 1 rubygems