Class: Ecoportal::API::V2::Page::Forces

Inherits:
Common::Content::CollectionModel show all
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

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Common::Content::CollectionModel

#[], #_doc_key, #_doc_pos, #_items, #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, #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

Note:
  • 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

Yields:

  • (force)

    to do some stuff with the force

Yield Parameters:

Returns:



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ecoportal/api/v2/page/forces.rb', line 37

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

#get_by_id(id) ⇒ Ecoportal::API::V2::Page::Force



16
17
18
19
20
# File 'lib/ecoportal/api/v2/page/forces.rb', line 16

def get_by_id(id)
  self.find do |force|
    force.id == id
  end
end

#get_by_name(name) ⇒ Array<Ecoportal::API::V2::Page::Force>



23
24
25
26
27
# File 'lib/ecoportal/api/v2/page/forces.rb', line 23

def get_by_name(name)
  self.select do |force|
    same_string?(force.name, name)
  end
end

#oozeObject



11
12
13
# File 'lib/ecoportal/api/v2/page/forces.rb', line 11

def ooze
  self._parent.ooze
end

#orderedArray<Ecoportal::API::V2::Page::Force>

Gets the forces ordered by weight (as they appear in the page)

Returns:



51
52
53
54
55
# File 'lib/ecoportal/api/v2/page/forces.rb', line 51

def ordered
  self.sort_by.with_index do |force, index|
    [force.weight, index]
  end
end