Class: MetadataPresenter::Route

Inherits:
Object
  • Object
show all
Defined in:
app/models/metadata_presenter/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service:, traverse_from:, row: 0, column: 0) ⇒ Route

Returns a new instance of Route.



6
7
8
9
10
11
12
13
# File 'app/models/metadata_presenter/route.rb', line 6

def initialize(service:, traverse_from:, row: 0, column: 0)
  @service = service
  @traverse_from = traverse_from
  @row = row
  @column = column
  @routes = []
  @flow_uuids = []
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



4
5
6
# File 'app/models/metadata_presenter/route.rb', line 4

def column
  @column
end

#flow_uuidsObject

Returns the value of attribute flow_uuids.



4
5
6
# File 'app/models/metadata_presenter/route.rb', line 4

def flow_uuids
  @flow_uuids
end

#routesObject

Returns the value of attribute routes.



4
5
6
# File 'app/models/metadata_presenter/route.rb', line 4

def routes
  @routes
end

#rowObject

Returns the value of attribute row.



4
5
6
# File 'app/models/metadata_presenter/route.rb', line 4

def row
  @row
end

#traverse_fromObject (readonly)

Returns the value of attribute traverse_from.



3
4
5
# File 'app/models/metadata_presenter/route.rb', line 3

def traverse_from
  @traverse_from
end

Instance Method Details

#traverseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/metadata_presenter/route.rb', line 15

def traverse
  @flow_uuid = traverse_from

  index = column
  until @flow_uuid.blank?
    if index > service.flow.size
      ActiveSupport::Notifications.instrument(
        'exceeded_total_flow_objects',
        message: 'Exceeded total number of flow objects'
      )
      break
    end

    @flow_uuids.push(@flow_uuid) unless @flow_uuids.include?(@flow_uuid)
    flow_object = service.flow_object(@flow_uuid)

    if flow_object.branch?
      destinations = destination_uuids(flow_object)
      # Take the first conditional destination and follow that until the end
      # of the route.
      @flow_uuid = destinations.shift

      # The remaining conditional destinations and the branch's default next
      # (otherwise) will be the starting point for a new Route object to be
      # traversed.
      # The default behaviour is that the next destination will be on the row
      # below this current route's row. This can be changed under certain
      # conditions in the Grid model.
      # Each of the destinations need to be placed in the column after the
      # current column.
      row_number = row + 1
      column_number = index + 1
      destinations.each do |uuid|
        @routes.push(
          MetadataPresenter::Route.new(
            service: service,
            traverse_from: uuid,
            row: row_number,
            column: column_number
          )
        )
        row_number += 1
      end
    else
      @flow_uuid = flow_object.default_next
    end

    index += 1
  end

  @flow_uuids
end