Class: MetadataPresenter::Service

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

Instance Attribute Summary

Attributes inherited from Metadata

#metadata

Instance Method Summary collapse

Methods inherited from Metadata

#==, #editor?, #id, #initialize, #method_missing, #respond_to_missing?, #to_json, #type, #uuid

Constructor Details

This class inherits a constructor from MetadataPresenter::Metadata

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MetadataPresenter::Metadata

Instance Method Details

#branchesObject



12
13
14
# File 'app/models/metadata_presenter/service.rb', line 12

def branches
  flow_objects.select { |flow| flow.type == 'flow.branch' }
end

#confirmation_pageObject



49
50
51
52
53
# File 'app/models/metadata_presenter/service.rb', line 49

def confirmation_page
  @confirmation_page ||= pages.find do |page|
    page.type == 'page.confirmation'
  end
end

#find_page_by_url(url) ⇒ Object



36
37
38
# File 'app/models/metadata_presenter/service.rb', line 36

def find_page_by_url(url)
  all_pages.find { |page| strip_slash(page.url) == strip_slash(url) }
end

#find_page_by_uuid(uuid) ⇒ Object



40
41
42
# File 'app/models/metadata_presenter/service.rb', line 40

def find_page_by_uuid(uuid)
  all_pages.find { |page| page.uuid == uuid }
end

#flow_object(uuid) ⇒ Object



16
17
18
19
20
# File 'app/models/metadata_presenter/service.rb', line 16

def flow_object(uuid)
  MetadataPresenter::Flow.new(uuid, .flow[uuid])
rescue StandardError
  nil
end

#flow_objectsObject



8
9
10
# File 'app/models/metadata_presenter/service.rb', line 8

def flow_objects
  flow.map { |uuid, flow| MetadataPresenter::Flow.new(uuid, flow) }
end

#metaObject



55
56
57
# File 'app/models/metadata_presenter/service.rb', line 55

def meta
  MetadataPresenter::Meta.new(configuration['meta'])
end

#next_page(from:) ⇒ Object



44
45
46
47
# File 'app/models/metadata_presenter/service.rb', line 44

def next_page(from:)
  current_page = find_page_by_url(from)
  pages[pages.index(current_page) + 1] if current_page.present?
end

#no_back_link?(current_page) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'app/models/metadata_presenter/service.rb', line 59

def no_back_link?(current_page)
  current_page == start_page ||
    current_page == confirmation_page ||
    current_page.standalone?
end

#page_with_component(uuid) ⇒ Object



65
66
67
68
69
# File 'app/models/metadata_presenter/service.rb', line 65

def page_with_component(uuid)
  pages.find do |page|
    Array(page.components).any? { |component| component.uuid == uuid }
  end
end

#pagesObject



2
3
4
5
6
# File 'app/models/metadata_presenter/service.rb', line 2

def pages
  @pages ||= .pages.map do |page|
    MetadataPresenter::Page.new(page, editor: editor?)
  end
end

#service_slugObject



32
33
34
# File 'app/models/metadata_presenter/service.rb', line 32

def service_slug
  service_name.parameterize
end

#standalone_pagesObject



22
23
24
25
26
# File 'app/models/metadata_presenter/service.rb', line 22

def standalone_pages
  @standalone_pages ||= .standalone_pages.map do |page|
    MetadataPresenter::Page.new(page, editor: editor?)
  end
end

#start_pageObject



28
29
30
# File 'app/models/metadata_presenter/service.rb', line 28

def start_page
  pages.first
end