Class: Ecoportal::API::GraphQL::Base::Force::BindingCollection
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Base::Force::BindingCollection
- Includes:
- Enumerable
- Defined in:
- lib/ecoportal/api/graphql/base/force/binding_collection.rb
Overview
Wraps the bindings array of a Force. Supports the v2 scripting interface: force.bindings.get_by_name(name) → [Binding, ...] force.bindings.add(field, name:) → queues addBinding command force.bindings.delete!(binding) → queues removeBinding command
Instance Method Summary collapse
-
#add(field, name:, type: 'field') ⇒ Object
Queue an addBinding command.
-
#delete!(binding_or_id) ⇒ Object
Queue a removeBinding command.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#get_by_name(name) ⇒ Object
Filter bindings by name (case-insensitive).
-
#initialize(raw, force:) ⇒ BindingCollection
constructor
A new instance of BindingCollection.
- #size ⇒ Object
Constructor Details
#initialize(raw, force:) ⇒ BindingCollection
Returns a new instance of BindingCollection.
13 14 15 16 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 13 def initialize(raw, force:) @force = force @bindings = Array(raw).map { |b| Force::Binding.new(b) } end |
Instance Method Details
#add(field, name:, type: 'field') ⇒ Object
Queue an addBinding command. field may be a GraphQL DataField object
(uses field.id as referenceId) or a raw ID string.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 26 def add(field, name:, type: 'field') ref_id = field.respond_to?(:id) ? field.id : field.to_s @force.queue_command( addBinding: { forceId: @force.id, name: name.to_s, referenceId: ref_id, type: type } ) self end |
#delete!(binding_or_id) ⇒ Object
Queue a removeBinding command. Accepts a Binding object or an ID string.
40 41 42 43 44 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 40 def delete!(binding_or_id) bid = binding_or_id.respond_to?(:id) ? binding_or_id.id : binding_or_id.to_s @force.queue_command(removeBinding: { id: bid }) self end |
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 46 def each(&block) @bindings.each(&block) end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 54 def empty? @bindings.empty? end |
#get_by_name(name) ⇒ Object
Filter bindings by name (case-insensitive).
19 20 21 22 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 19 def get_by_name(name) target = name.to_s.downcase @bindings.select { |b| b.name.to_s.downcase == target } end |
#size ⇒ Object
50 51 52 |
# File 'lib/ecoportal/api/graphql/base/force/binding_collection.rb', line 50 def size @bindings.size end |