Class: Ecoportal::API::V2::Page::Components
- Inherits:
-
Common::Content::CollectionModel
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Common::Content::CollectionModel
- Ecoportal::API::V2::Page::Components
- Defined in:
- lib/ecoportal/api/v2/page/components.rb
Constant Summary
Constants included from Common::Content::DoubleModel::Diffable
Common::Content::DoubleModel::Diffable::DIFF_CLASS
Constants included from Common::Content::DoubleModel::Base
Common::Content::DoubleModel::Base::NOT_USED
Instance Attribute Summary
Attributes included from Common::Content::DoubleModel::Parented
Instance Method Summary collapse
-
#add(doc: nil, label: doc && doc['label'], type: doc && doc['type']) {|field| ... } ⇒ Ecoportal::API::V2::Page::Component
It creates a new component.
-
#get_by_id(id) ⇒ Ecoportal::API::V2::Page::Component
The field with
id. -
#get_by_name(name, type: nil) ⇒ Array<Ecoportal::API::V2::Page::Component>
The fields that match
name. -
#get_by_type(type) ⇒ Array<Ecoportal::API::V2::Page::Component>
The fields of that
type. -
#multi_section ⇒ Array<Ecoportal::API::V2::Page::Component>
Fields belonging to more than one section.
-
#ooze ⇒ Object
self.order_matters = true.
-
#unattached ⇒ Array<Ecoportal::API::V2::Page::Component>
orphaned fields (with no section).
Methods inherited from Common::Content::CollectionModel
Methods included from Common::Content::Includer
Methods inherited from Common::Content::DoubleModel
Methods included from Common::Content::DoubleModel::Diffable
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::CollectionModel
Instance Method Details
#add(doc: nil, label: doc && doc['label'], type: doc && doc['type']) {|field| ... } ⇒ Ecoportal::API::V2::Page::Component
Note:
- You can use either
typeandlabelordoc
It creates a new component
53 54 55 56 57 58 59 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 53 def add(doc: nil, label: doc && doc['label'], type: doc && doc['type']) fld_doc = doc ? JSON.parse(doc.to_json) : component_class.new_doc(type: type) upsert!(fld_doc) do |fld| fld.label = label unless doc yield(fld) if block_given? end end |
#get_by_id(id) ⇒ Ecoportal::API::V2::Page::Component
Returns the field with id.
21 22 23 24 25 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 21 def get_by_id(id) find do |comp| comp.id == id end end |
#get_by_name(name, type: nil) ⇒ Array<Ecoportal::API::V2::Page::Component>
Returns the fields that match name.
37 38 39 40 41 42 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 37 def get_by_name(name, type: nil) pool = type ? get_by_type(type) : self pool.select do |comp| same_string?(comp.label, name) end end |
#get_by_type(type) ⇒ Array<Ecoportal::API::V2::Page::Component>
Returns the fields of that type.
28 29 30 31 32 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 28 def get_by_type(type) select do |comp| comp.type.downcase == type.to_s.strip.downcase end end |
#multi_section ⇒ Array<Ecoportal::API::V2::Page::Component>
Returns fields belonging to more than one section.
67 68 69 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 67 def multi_section select(&:multi_section?) end |
#ooze ⇒ Object
self.order_matters = true
16 17 18 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 16 def ooze _parent.ooze end |
#unattached ⇒ Array<Ecoportal::API::V2::Page::Component>
Returns orphaned fields (with no section).
62 63 64 |
# File 'lib/ecoportal/api/v2/page/components.rb', line 62 def unattached reject(&:attached?) end |