Class: RailsWorkflow::Operation

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
HasContext, OperationStatus, RailsWorkflow::Operations::Assignments, RailsWorkflow::Operations::Dependencies
Defined in:
app/models/rails_workflow/operation.rb

Overview

Operation is a key building block for a Rails Workflow. This model is used to save operation meta data, describe relation with operation context etc.

Direct Known Subclasses

EventOperation, UserOperation

Constant Summary

Constants included from Status

Status::CANCELED, Status::DONE, Status::ERROR, Status::IN_PROGRESS, Status::NOT_STARTED, Status::ROLLBACK, Status::SKIPPED, Status::WAITING

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#managerObject



45
46
47
# File 'app/models/rails_workflow/operation.rb', line 45

def manager
  @manager ||= process.manager
end

Instance Method Details

#assigned_to?(user) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/rails_workflow/operation.rb', line 59

def assigned_to?(user)
  assignment && assignment == user
end

#can_be_continued_by?(user, current_operation) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
87
# File 'app/models/rails_workflow/operation.rb', line 83

def can_be_continued_by?(user, current_operation)
  waiting? &&
    assigned_to?(user) &&
    (current_operation.nil? || current_operation != self)
end

#can_be_started_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/rails_workflow/operation.rb', line 55

def can_be_started_by?(user)
  waiting? && can_be_assigned?(user) && assignment.nil?
end

#can_start?Boolean

This method allows you to add requirements for operation to start. For example some operation can’t start because of some process or overall system conditions. By default any operation can start :)

Returns:

  • (Boolean)


71
72
73
# File 'app/models/rails_workflow/operation.rb', line 71

def can_start?
  status.in? [Status::NOT_STARTED, Status::IN_PROGRESS]
end

#completable?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/rails_workflow/operation.rb', line 79

def completable?
  child_process_done?
end

#completed?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/rails_workflow/operation.rb', line 75

def completed?
  completed_statuses.include? status
end

#executeObject



63
64
65
# File 'app/models/rails_workflow/operation.rb', line 63

def execute
  true
end

#instructionObject



37
38
39
# File 'app/models/rails_workflow/operation.rb', line 37

def instruction
  template.instruction
end

#tagObject



41
42
43
# File 'app/models/rails_workflow/operation.rb', line 41

def tag
  read_attribute(:tag) || template.tag
end

#waiting?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/rails_workflow/operation.rb', line 51

def waiting?
  status.in? Operation.user_ready_statuses
end