module Zenaton::Concerns::Workflow

Utility methods for classes that interact with workflows Requires an instance variable @workflow to work

Constants

MAX_ID_SIZE

Private Instance Methods

validate_custom_id() click to toggle source

Validation for the return value of the [#id] method

# File lib/zenaton/concerns/workflow.rb, line 29
def validate_custom_id
  return unless @workflow.try(:id).present?

  validate_custom_id_type
  validate_custom_id_value
end
validate_custom_id_type() click to toggle source

Only allow String and Integers as custom IDs

# File lib/zenaton/concerns/workflow.rb, line 37
def validate_custom_id_type
  valid_types = [String, Integer]
  return if valid_types.any? { |type| @workflow.id.is_a?(type) }

  raise InvalidArgumentError,
        'Provided ID must be a string or an integer' \
end
validate_custom_id_value() click to toggle source

Enforce maximum size on custom IDs

# File lib/zenaton/concerns/workflow.rb, line 46
def validate_custom_id_value
  return if @workflow.id.to_s.length <= MAX_ID_SIZE

  raise InvalidArgumentError,
        "Provided Id must not exceed #{MAX_ID_SIZE} bytes"
end
workflow_name() click to toggle source

Determines the name of the workflow

# File lib/zenaton/concerns/workflow.rb, line 20
def workflow_name
  if @workflow.is_a? Workflows::Version
    @workflow.current_implementation.class.name
  else
    @workflow.class.name
  end
end