Module: WorkflowTemplate::State

Defined in:
lib/workflow_template/state.rb,
lib/workflow_template/state/meta.rb,
lib/workflow_template/state/final.rb,
lib/workflow_template/state/adapter.rb,
lib/workflow_template/state/abstract.rb,
lib/workflow_template/state/normalizer.rb,
lib/workflow_template/state/validation.rb,
lib/workflow_template/state/intermediate.rb,
lib/workflow_template/state/class_methods.rb

Defined Under Namespace

Modules: Abstract, Adapter, ClassMethods, Intermediate, Validation Classes: Final, Meta, Normalizer

Constant Summary collapse

STRATEGIES =
%i[merge update].freeze

Class Method Summary collapse

Class Method Details

.normalize_transition_strategy(strategy) ⇒ Object

Raises:



9
10
11
12
13
14
# File 'lib/workflow_template/state.rb', line 9

def self.normalize_transition_strategy(strategy)
  strategy = strategy.to_sym
  raise Error, "Unimplemented strategy: '#{strategy}'" unless STRATEGIES.include?(strategy)

  strategy
end

.state_class(adapter) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/workflow_template/state.rb', line 16

def self.state_class(adapter)
  state_classes[adapter] ||= Class.new do
    include State::Intermediate
    extend State::ClassMethods

    raise Error, "Invalid adapter: #{adapter}" unless State.valid_adapter?(adapter)

    include adapter::InstanceMethods
    extend adapter::ClassMethods

    private_class_method :new
  end
end

.state_classesObject



37
38
39
# File 'lib/workflow_template/state.rb', line 37

def self.state_classes
  @state_classes ||= {}
end

.valid_adapter?(adapter) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/workflow_template/state.rb', line 30

def self.valid_adapter?(adapter)
  adapter.constants.include?(:InstanceMethods) &&
    adapter::InstanceMethods.included_modules.include?(Adapter::Abstract::InstanceMethods) &&
    adapter.constants.include?(:ClassMethods) &&
    adapter::ClassMethods.included_modules.include?(Adapter::Abstract::ClassMethods)
end