Class: Ecoportal::API::V2::Page::Section
- Inherits:
-
Common::Content::DoubleModel
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Section
- Defined in:
- lib/ecoportal/api/v2/page/section.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
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Common::Content::DoubleModel
#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_multiple, embeds_one, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passdate, passkey, passthrough, #pretty_print, #replace_doc, #reset!, #root, #to_json
Methods included from Common::Content::ClassHelpers
#instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #used_param?
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel
Class Method Details
.new_doc(split: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ecoportal/api/v2/page/section.rb', line 7 def new_doc(split: false) { "id" => new_uuid, "type" => split ? "split" : "content", "weight" => 9999 }.tap do |out| component_ids = if split { "left_component_ids" => [], "right_component_ids" => [] } else { "component_ids" => [] } end out.merge!(component_ids) end end |
Instance Method Details
#all_component_ids ⇒ Object
38 39 40 41 |
# File 'lib/ecoportal/api/v2/page/section.rb', line 38 def all_component_ids return component_ids.to_a unless split? left_component_ids.to_a | right_component_ids.to_a end |
#component?(id) ⇒ Boolean
43 44 45 |
# File 'lib/ecoportal/api/v2/page/section.rb', line 43 def component?(id) all_component_ids.include?(id) end |
#components ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ecoportal/api/v2/page/section.rb', line 47 def components fld_ids = all_component_ids root.components.values_at(*fld_ids).select.with_index do |fld, i| puts "Warning: field #{id} points to missing field #{fld_ids[i]}" if !fld fld && (!block_given? || yield(fld)) end end |
#split? ⇒ Boolean
34 35 36 |
# File 'lib/ecoportal/api/v2/page/section.rb', line 34 def split? doc && doc["type"] == "split" end |