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!, doc_class, #each, #empty?, #include?, #initialize, #items_class, items_key, items_key=, klass?, #length, new_item, #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, #replace_doc, #reset!, #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
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 49 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
19 20 21 22 23 24 25 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 19 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
28 29 30 31 32 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 28 def get_by_id(id) self.find do |force| force.id == id end end |
#get_by_name(name) ⇒ Array<Ecoportal::API::V2::Page::Force>
35 36 37 38 39 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 35 def get_by_name(name) self.select do |force| same_string?(force.name, name) end end |
#ooze ⇒ Object
11 12 13 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 11 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)
63 64 65 66 67 |
# File 'lib/ecoportal/api/v2/page/forces.rb', line 63 def ordered self.sort_by.with_index do |force, index| [force.weight, index] end end |