Sha256: 91df1c17943481d958ef496533b962153a40302cf4ff1416cdc48dcb951fbe1a

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

module StateMachines::Task
  def self.included(base)
    base.extend ClassMethods
    
    base.class_eval do
      include Model::MongoDb::StateVersionAttributes
      
      attr_accessor :current_user
      
      const_set 'STATES', [:new, :assigned, :under_supervision, :completed]
      const_set 'EVENTS', [:assign, :cancel, :review, :follow_up, :complete]
      
      state_machine :state, initial: :new do
        event :assign do
          transition :new => :assigned
        end
        
        state :assigned do
          validates :user_id, presence: true
        end
        
        event :cancel do 
          transition :assigned => :new
        end
       
        event :review do
          transition :assigned => :under_supervision
        end
        
        state :under_supervision do
          # TODO: move logic of Workflow::TasksController#update here
          #validates_associated :result
        end
       
        event :follow_up do 
          transition [:under_supervision, :completed] => :assigned
        end
        
        event :complete do
          # TODO: complete the story through observer
          transition :under_supervision => :completed
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
voluntary-0.1.0 app/models/state_machines/task.rb
voluntary-0.1.0.rc4 app/models/state_machines/task.rb
voluntary-0.1.0.rc3 app/models/state_machines/task.rb
voluntary-0.1.0.rc2 app/models/state_machines/task.rb
voluntary-0.1.0.rc1 app/models/state_machines/task.rb
voluntary-0.0.3 app/models/state_machines/task.rb
voluntary-0.0.2 app/models/state_machines/task.rb
voluntary-0.0.1 app/models/state_machines/task.rb