Module: Workflower::ActsAsWorkflower::ClassMethods
- Defined in:
- lib/workflower/acts_as_workflower.rb
Instance Method Summary collapse
- #workflower(default_workflow_id:, source:, workflower_state_column_name: "workflow_state", skip_setting_initial_state: false) ⇒ Object
- #workflower_abilities(workflow_selector: nil) ⇒ Object
Instance Method Details
#workflower(default_workflow_id:, source:, workflower_state_column_name: "workflow_state", skip_setting_initial_state: false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/workflower/acts_as_workflower.rb', line 70 def workflower(default_workflow_id:, source:, workflower_state_column_name: "workflow_state", skip_setting_initial_state: false) raise Workflower::WorkflowerError, "Options can't be blank" if source.blank? || default_workflow_id.blank? cattr_accessor :source, default: source cattr_accessor :workflower_state_column_name, default: workflower_state_column_name cattr_accessor :default_workflow_id, default: default_workflow_id self.workflower_state_column_name = workflower_state_column_name self.source = source self.default_workflow_id = default_workflow_id # self.validates "#{workflow_model.tableize.singularize}_id", presence: true before_create :set_initial_state unless skip_setting_initial_state end |
#workflower_abilities(workflow_selector: nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/workflower/acts_as_workflower.rb', line 85 def workflower_abilities(workflow_selector: nil) # workflow_selector helps dynamic transition selection when we have multiple workflows that needs to change depending on the workflow_selector. load = source.new(new).get_workflows.values.flatten.uniq unless workflow_selector.present? load = source.new(workflow_selector.to_sym).get_workflows.values.flatten.uniq if workflow_selector.present? unless load.blank? # transitions = load.transitions.where("(metadata->>'roles') IS NOT NULL") transitions = load.select { |item| item.try(:[], :metadata).try(:key?, :roles) } roles = transitions.map { |item| item[:metadata][:roles] }.flatten.uniq roles_hash = {} roles.each do |role| roles_hash[role] = transitions.select { |trans| trans[:metadata][:roles].to_a.include?(role) }.map { |item| item[:event] }.uniq end roles_hash end end |