Class: Ecoportal::API::GraphQL::Base::Force::Collection
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Base::Force::Collection
- Includes:
- Enumerable
- Defined in:
- lib/ecoportal/api/graphql/base/force/collection.rb
Overview
Wraps a page's forces array. Provides the v2 scripting interface: page.forces.get_by_name(name) → [Force, ...]
Instance Method Summary collapse
-
#dirty? ⇒ Boolean
True if any force has uncommitted script changes or pending binding commands.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#get_by_name(name) ⇒ Object
Filter forces by name (case-insensitive).
-
#initialize(raw) ⇒ Collection
constructor
A new instance of Collection.
-
#pending_commands ⇒ Object
All pending commands across all forces (editForce, addBinding, removeBinding).
- #size ⇒ Object
Constructor Details
#initialize(raw) ⇒ Collection
Returns a new instance of Collection.
11 12 13 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 11 def initialize(raw) @forces = Array(raw).map { |f| Force.new(f) } end |
Instance Method Details
#dirty? ⇒ Boolean
True if any force has uncommitted script changes or pending binding commands.
22 23 24 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 22 def dirty? @forces.any?(&:dirty?) end |
#each(&block) ⇒ Object
31 32 33 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 31 def each(&block) @forces.each(&block) end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 39 def empty? @forces.empty? end |
#get_by_name(name) ⇒ Object
Filter forces by name (case-insensitive).
16 17 18 19 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 16 def get_by_name(name) target = name.to_s.downcase @forces.select { |f| f.name.to_s.downcase == target } end |
#pending_commands ⇒ Object
All pending commands across all forces (editForce, addBinding, removeBinding).
27 28 29 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 27 def pending_commands @forces.flat_map(&:all_pending_commands) end |
#size ⇒ Object
35 36 37 |
# File 'lib/ecoportal/api/graphql/base/force/collection.rb', line 35 def size @forces.size end |