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 inherited from Common::Content::DoubleModel
Common::Content::DoubleModel::NOT_USED
Constants included from Common::Content::ClassHelpers
Common::Content::ClassHelpers::NOT_USED
Instance Attribute Summary
Attributes inherited from Common::Content::DoubleModel
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
#[], #_doc_key, #_doc_pos, #_items, #clear, #delete!, #each, #empty?, #include?, #initialize, #items_class, items_key, items_key=, klass?, #length, new_item, new_item_class_based?, #present?, #upsert!, #values_at
Methods inherited from Common::Content::DoubleModel
#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_many, embeds_one, enforce!, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passboolean, passdate, passforced, passkey, passthrough, #print_pretty, read_only!, read_only?, #read_only?, #replace_doc, #reset!, #resolved_doc_key, #root, #to_json
Methods included from Common::Content::ClassHelpers
#inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #uid, #used_param?
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
- You can use either
type
andlabel
ordoc
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 |