Class: Ecoportal::API::V2::Page::Forces
- Inherits:
-
Common::Content::CollectionModel
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Common::Content::CollectionModel
- Ecoportal::API::V2::Page::Forces
- Defined in:
- lib/ecoportal/api/v2/page/forces.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(name, pos: NOT_USED, before: NOT_USED, after: NOT_USED) {|force| ... } ⇒ Ecoportal::API::V2::Page::Force
Creates a new
force
. -
#bindings_by_reference(only_winner: false) ⇒ Hash
Helper to optimize binding searches.
- #get_by_id(id) ⇒ Ecoportal::API::V2::Page::Force
- #get_by_name(name) ⇒ Array<Ecoportal::API::V2::Page::Force>
- #ooze ⇒ Object
-
#ordered ⇒ Array<Ecoportal::API::V2::Page::Force>
Gets the forces ordered by
weight
(as they appear in the page).
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(name, pos: NOT_USED, before: NOT_USED, after: NOT_USED) {|force| ... } ⇒ Ecoportal::API::V2::Page::Force
- It won't fix weights unless all the forces of the ooze are present
- This means that it doesn't fix forces weights on stages, as shared forces could change order in other stages
Creates a new force
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 50 def add(name, pos: NOT_USED, before: NOT_USED, after: NOT_USED) force_doc = force_class.new_doc upsert!(force_doc) do |force| #, pos: pos, before: before, after: after) do |section| force.name = name if weight = scope_weight(force, pos: pos, before: before, after: after) force.weight = weight end fix_weights! yield(force) if block_given? end end |
#bindings_by_reference(only_winner: false) ⇒ Hash
Helper to optimize binding searches
20 21 22 23 24 25 26 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 20 def bindings_by_reference(only_winner: false) self.each_with_object({}) do |force, out| force.bindings.by_reference(only_winner: only_winner).each do |ref, bindings| (out[ref] ||= []).push(*bindings) end end end |
#get_by_id(id) ⇒ Ecoportal::API::V2::Page::Force
29 30 31 32 33 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 29 def get_by_id(id) self.find do |force| force.id == id end end |
#get_by_name(name) ⇒ Array<Ecoportal::API::V2::Page::Force>
36 37 38 39 40 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 36 def get_by_name(name) self.select do |force| same_string?(force.name, name) end end |
#ooze ⇒ Object
12 13 14 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 12 def ooze self._parent.ooze end |
#ordered ⇒ Array<Ecoportal::API::V2::Page::Force>
Gets the forces ordered by weight
(as they appear in the page)
64 65 66 67 68 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 64 def ordered self.sort_by.with_index do |force, index| [force.weight, index] end end |