Class: WAB::UI::Flow

Inherits:
Controller show all
Defined in:
lib/wab/ui/flow.rb

Overview

A controller that provides a description of the UI for the WAB UI reference implementation.

Direct Known Subclasses

MultiFlow, RestFlow

Instance Attribute Summary collapse

Attributes inherited from Controller

#shell

Instance Method Summary collapse

Methods inherited from Controller

#handle

Constructor Details

#initialize(shell) ⇒ Flow

Returns a new instance of Flow.



12
13
14
15
# File 'lib/wab/ui/flow.rb', line 12

def initialize(shell)
  super
  @displays = {}
end

Instance Attribute Details

#displaysObject (readonly)

Returns the value of attribute displays.



10
11
12
# File 'lib/wab/ui/flow.rb', line 10

def displays
  @displays
end

#entryObject

Returns the value of attribute entry.



9
10
11
# File 'lib/wab/ui/flow.rb', line 9

def entry
  @entry
end

Instance Method Details

#add_display(display, entry = false) ⇒ Object

Adds a display to the flow.

Raises:



18
19
20
21
22
23
# File 'lib/wab/ui/flow.rb', line 18

def add_display(display, entry=false)
  name = display.name
  raise DuplicateError.new(name) if @displays.has_key?(name)
  @displays[name] = display
  @entry = name if entry
end

#get_display(name) ⇒ Object



25
26
27
# File 'lib/wab/ui/flow.rb', line 25

def get_display(name)
  @displays[name]
end

#read(path, _query) ⇒ Object

Returns a description of the UI to be used. If a display name is includd in the path thenn just that display description is returned.

path

array of tokens in the path.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wab/ui/flow.rb', line 33

def read(path, _query)
  results = []
  path_pos = @shell.path_pos
  if path_pos + 2 == path.length
    # Return the description of the named display.
    name = path[path_pos + 1]
    display = get_display(name)
    display[:entry] = true if !display.nil? && display.name == @entry
    results << {id: name, data: display.spec} unless display.nil?
  else
    @displays.each_value { |display|
      spec = display.spec
      spec[:entry] = true if display.name == @entry
      results << spec
    }
  end
  @shell.data({code: 0, results: results})
end