Class: Textus::Workflow::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/workflow/registry.rb

Defined Under Namespace

Classes: UnknownWorkflow

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_definitions) ⇒ Registry

Returns a new instance of Registry.



20
21
22
23
24
25
26
27
28
29
# File 'lib/textus/workflow/registry.rb', line 20

def initialize(workflow_definitions)
  @definitions = workflow_definitions
  @by_event = {}
  @by_type  = {}

  workflow_definitions.each do |wf|
    @by_type[wf.type] = wf
    wf.handled_events.each { |ev| (@by_event[ev] ||= []) << wf }
  end
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



18
19
20
# File 'lib/textus/workflow/registry.rb', line 18

def definitions
  @definitions
end

Class Method Details

.load_all(root) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/textus/workflow/registry.rb', line 9

def self.load_all(root)
  geometry = Textus::Protocol::Layout.new(root)
  return [] unless File.directory?(geometry.workflow_dir)

  Workflow::DSL::Definition.clear_registered
  Dir.glob(File.join(geometry.workflow_dir, "**", "*.rb")).each { |path| load path }
  Workflow::DSL::Definition.definitions
end

Instance Method Details

#for(workflow_type) ⇒ Object



35
36
37
# File 'lib/textus/workflow/registry.rb', line 35

def for(workflow_type)
  @by_type[workflow_type.to_s] or raise(UnknownWorkflow.new("Unknown workflow type: #{workflow_type}"))
end

#match_for_key(key) ⇒ Object



39
40
41
# File 'lib/textus/workflow/registry.rb', line 39

def match_for_key(key)
  @definitions.find { |wf| wf.match?(key) }
end

#workflows_for(event_type) ⇒ Object



31
32
33
# File 'lib/textus/workflow/registry.rb', line 31

def workflows_for(event_type)
  @by_event.fetch(event_type.to_s, [])
end