Class: MetadataPresenter::Page

Inherits:
Metadata
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/metadata_presenter/page.rb

Constant Summary collapse

NOT_EDITABLE =
i[
  _uuid
  _id
  _type
  add_component
  add_extra_component
].freeze
QUESTION_PAGES =
%w[page.singlequestion page.multiplequestions].freeze
USES_HEADING =
%w[
  page.content
  page.checkanswers
  page.confirmation
  page.multiplequestions
  page.exit
].freeze
END_OF_ROUTE_PAGES =
%w[
  page.checkanswers
  page.confirmation
  page.exit
].freeze

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

#all_componentsObject



37
38
39
# File 'app/models/metadata_presenter/page.rb', line 37

def all_components
  [components, extra_components].flatten.compact
end

#componentsObject



41
42
43
# File 'app/models/metadata_presenter/page.rb', line 41

def components
  to_components(.components, collection: :components)
end

#content_componentsObject



53
54
55
# File 'app/models/metadata_presenter/page.rb', line 53

def content_components
  all_components.select(&:content?)
end

#editable_attributesObject



29
30
31
# File 'app/models/metadata_presenter/page.rb', line 29

def editable_attributes
  to_h.reject { |k, _| k.in?(NOT_EDITABLE) }
end

#end_of_route?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/metadata_presenter/page.rb', line 99

def end_of_route?
  type.in?(END_OF_ROUTE_PAGES)
end

#extra_componentsObject



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

def extra_components
  to_components(.extra_components, collection: :extra_components)
end

#find_component_by_uuid(uuid) ⇒ Object



33
34
35
# File 'app/models/metadata_presenter/page.rb', line 33

def find_component_by_uuid(uuid)
  all_components.find { |component| component.uuid == uuid }
end

#input_componentsObject



49
50
51
# File 'app/models/metadata_presenter/page.rb', line 49

def input_components
  all_components.reject(&:content?)
end

#question_page?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/metadata_presenter/page.rb', line 89

def question_page?
  type.in?(QUESTION_PAGES)
end

#standalone?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/metadata_presenter/page.rb', line 85

def standalone?
  type == 'page.standalone'
end

#supported_components_by_type(type) ⇒ Object



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

def supported_components_by_type(type)
  supported = supported_components(raw_type)[type]

  all_components.select do |component|
    supported.include?(component.type)
  end
end

#supported_content_componentsObject



77
78
79
# File 'app/models/metadata_presenter/page.rb', line 77

def supported_content_components
  supported_components(raw_type)[:content]
end

#supported_input_componentsObject



73
74
75
# File 'app/models/metadata_presenter/page.rb', line 73

def supported_input_components
  supported_components(raw_type)[:input]
end

#templateObject



69
70
71
# File 'app/models/metadata_presenter/page.rb', line 69

def template
  "metadata_presenter/#{type.gsub('.', '/')}"
end

#titleObject



93
94
95
96
97
# File 'app/models/metadata_presenter/page.rb', line 93

def title
  return heading if heading?

  components.first.humanised_title
end

#to_partial_pathObject



65
66
67
# File 'app/models/metadata_presenter/page.rb', line 65

def to_partial_path
  type.gsub('.', '/')
end

#upload_componentsObject



81
82
83
# File 'app/models/metadata_presenter/page.rb', line 81

def upload_components
  components.select(&:upload?)
end