Sha256: a2f2cd16777881d0b6a78c97b0037f43ebc11992f588654559fc5a034d0174d1

Contents?: true

Size: 1.89 KB

Versions: 25

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true
module Sipity
  # A named thing that happens within the bounds of a :workflow.
  #
  # When a Sipity::WorkflowAction is taken, it may:
  # * Advance the state to a new Sipity::WorkflowState (as defined by
  #   the :resulting_workflow_state relation)
  # * Deliver one or more notifications (as defined by the
  #   :notifiable_contexts relation)
  #
  # @see Hyrax::Forms::WorkflowActionForm
  class WorkflowAction < ActiveRecord::Base
    self.table_name = 'sipity_workflow_actions'

    belongs_to :workflow, class_name: 'Sipity::Workflow'

    # Not all workflow actions will change state. For example, leaving a comment
    # is an action, but likely not one to advance the state. Whereas, remove from
    # public view is something that would likely advance the state.
    belongs_to :resulting_workflow_state,
               optional: true,
               class_name: 'Sipity::WorkflowState'

    # In what states can this (eg. self) action be taken
    has_many :workflow_state_actions, dependent: :destroy, class_name: 'Sipity::WorkflowStateAction'

    # These are arbitrary "lambdas" that you can call when the action is taken
    #   * Need to send an email?
    #   * Need to publish a WEBHOOK callback?
    #   * Need to update the ACLs for the record?
    has_many :triggered_methods, dependent: :destroy, class_name: 'Sipity::Method'

    has_many :notifiable_contexts,
             dependent: :destroy,
             as: :scope_for_notification,
             class_name: 'Sipity::NotifiableContext'

    ##
    # @param [Object] input
    # @return [String]
    def self.name_for(input, &block)
      result = case input
               when String, Symbol
                 input.to_s.sub(/[\?\!]\Z/, '')
               when Sipity::WorkflowAction
                 input.name
               end
      Sipity.handle_conversion(input, result, :to_sipity_action_name, &block)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/models/sipity/workflow_action.rb
hyrax-5.0.0 app/models/sipity/workflow_action.rb
hyrax-5.0.0.rc3 app/models/sipity/workflow_action.rb
hyrax-5.0.0.rc2 app/models/sipity/workflow_action.rb
hyrax-5.0.0.rc1 app/models/sipity/workflow_action.rb
hyrax-3.6.0 app/models/sipity/workflow_action.rb
hyrax-4.0.0 app/models/sipity/workflow_action.rb
hyrax-4.0.0.rc3 app/models/sipity/workflow_action.rb
hyrax-4.0.0.rc2 app/models/sipity/workflow_action.rb
hyrax-4.0.0.rc1 app/models/sipity/workflow_action.rb
hyrax-3.5.0 app/models/sipity/workflow_action.rb
hyrax-4.0.0.beta2 app/models/sipity/workflow_action.rb
hyrax-3.4.2 app/models/sipity/workflow_action.rb
hyrax-4.0.0.beta1 app/models/sipity/workflow_action.rb
hyrax-3.4.1 app/models/sipity/workflow_action.rb
hyrax-3.4.0 app/models/sipity/workflow_action.rb
hyrax-3.3.0 app/models/sipity/workflow_action.rb
hyrax-3.2.0 app/models/sipity/workflow_action.rb
hyrax-3.1.0 app/models/sipity/workflow_action.rb
hyrax-3.0.2 app/models/sipity/workflow_action.rb