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, previous_flow_uuid: nil, conditional_uuid: nil) ⇒ Route

Returns a new instance of Route.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/metadata_presenter/route.rb', line 7

def initialize(service:, traverse_from:, row: 0, column: 0,
               previous_flow_uuid: nil, conditional_uuid: nil)
  @service = service
  @traverse_from = traverse_from
  @row = row
  @column = column
  @previous_flow_uuid = previous_flow_uuid
  @conditional_uuid = conditional_uuid
  @previous_uuids = setup_previous_uuids
  @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

#conditional_uuidObject

Returns the value of attribute conditional_uuid.



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

def conditional_uuid
  @conditional_uuid
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

#previous_flow_uuidObject

Returns the value of attribute previous_flow_uuid.



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

def previous_flow_uuid
  @previous_flow_uuid
end

#previous_uuidsObject

Returns the value of attribute previous_uuids.



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

def previous_uuids
  @previous_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



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
# File 'app/models/metadata_presenter/route.rb', line 20

def traverse
  @flow_uuid = traverse_from
  index = column
  previous_uuid = previous_flow_uuid || ''

  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 = branch_destinations(flow_object)
      # Take the first conditional destination and follow that until the end
      # of the route.
      first_conditional = destinations.shift
      set_first_conditional_previous_flow(flow_object.uuid, first_conditional)
      create_destination_routes(
        previous_flow_uuid: flow_object.uuid,
        destinations:,
        row:,
        column: index
      )

      @flow_uuid = first_conditional[:next]
    else
      @flow_uuid = flow_object.default_next
    end

    unless previous_uuids.key?(flow_object.uuid)
      set_previous_flow(uuid: flow_object.uuid, previous_flow_uuid: previous_uuid)
    end
    previous_uuid = flow_object.uuid
    index += 1
  end

  @flow_uuids
end