Class: Ecoportal::API::GraphQL::Base::Page::Section

Inherits:
Logic::BaseModel show all
Defined in:
lib/ecoportal/api/graphql/base/page/section.rb

Overview

Wraps a SectionUnion doc (ContentSection or SplitSection). Provides access to heading, type, and data fields within the section.

Direct Known Subclasses

Model::Page::Section

Constant Summary

Constants included from Common::GraphQL::Model::Diffable

Common::GraphQL::Model::Diffable::DIFF_CLASS

Instance Method Summary collapse

Methods included from Concerns::SnakeCamelAccess

#method_missing, #respond_to_missing?

Methods included from Common::GraphQL::Model::AsInput

#as_input

Methods included from Common::GraphQL::Model::Diffable

#as_update, #dirty?

Constructor Details

#initialize(raw_doc = {}) ⇒ Section

Returns a new instance of Section.



17
18
19
20
21
# File 'lib/ecoportal/api/graphql/base/page/section.rb', line 17

def initialize(raw_doc = {})
  raw_doc = raw_doc.dup if raw_doc.is_a?(Hash)
  raw_doc['type'] ||= raw_doc['__typename'] if raw_doc.is_a?(Hash)
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ecoportal::API::GraphQL::Concerns::SnakeCamelAccess

Instance Method Details

#componentsObject Also known as: data_fields

All data fields in this section. ContentSection → dataFields SplitSection → leftDataFields + rightDataFields (merged)



26
27
28
29
30
31
# File 'lib/ecoportal/api/graphql/base/page/section.rb', line 26

def components
  all = (doc['dataFields']      || []) +
        (doc['leftDataFields']  || []) +
        (doc['rightDataFields'] || [])
  DataField::Collection.from_doc(all)
end

#content_section?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ecoportal/api/graphql/base/page/section.rb', line 36

def content_section?
  type.to_s == 'ContentSection'
end

#split_section?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ecoportal/api/graphql/base/page/section.rb', line 40

def split_section?
  type.to_s == 'SplitSection'
end