Class: Ecoportal::API::GraphQL::Base::Force

Inherits:
Logic::BaseModel show all
Defined in:
lib/ecoportal/api/graphql/base/force.rb,
lib/ecoportal/api/graphql/base/force/binding.rb,
lib/ecoportal/api/graphql/base/force/collection.rb,
lib/ecoportal/api/graphql/base/force/binding_collection.rb

Overview

Represents a Force — a AngularJS/LISP snippet that implements conditional field behaviour on a page stage. Forces are queried as part of a page when forces are explicitly included in the query fragment.

Read access is via the page's force collection: force = page.forces.get_by_name('Workflow (S1)').first force.custom_script # → current LISP script force.bindings.get_by_name('top-txt') # → [Binding, ...]

Write access queues workflow commands executed after process_ooze: force.custom_script = new_script # → queues editForce command force.bindings.add(field, name: 'bind-name') # → queues addBinding force.bindings.delete!(binding) # → queues removeBinding

Defined Under Namespace

Classes: Binding, BindingCollection, Collection

Constant Summary

Constants included from Common::GraphQL::Model::Diffable

Common::GraphQL::Model::Diffable::DIFF_CLASS

Instance Method Summary collapse

Methods included from Concerns::SnakeCamelAccess

#method_missing, #respond_to_missing?

Methods included from Common::GraphQL::Model::AsInput

#as_input

Methods included from Common::GraphQL::Model::Diffable

#as_update

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ecoportal::API::GraphQL::Concerns::SnakeCamelAccess

Instance Method Details

#all_pending_commandsObject

Collect all commands including the script edit if dirty.



55
56
57
58
59
60
# File 'lib/ecoportal/api/graphql/base/force.rb', line 55

def all_pending_commands
  cmds = []
  cmds << { editForce: { id: id, customScript: doc['customScript'] } } if @_custom_script_dirty
  cmds.concat(pending_commands)
  cmds
end

#bindingsObject



27
28
29
# File 'lib/ecoportal/api/graphql/base/force.rb', line 27

def bindings
  @bindings ||= Force::BindingCollection.new(doc['bindings'] || [], force: self)
end

#custom_script=(new_script) ⇒ Object

v2 compat: scripts read and write custom_script directly. Writing queues an editForce workflow command consumed by ForceCompat.



33
34
35
36
37
38
# File 'lib/ecoportal/api/graphql/base/force.rb', line 33

def custom_script=(new_script)
  return if doc['customScript'] == new_script

  doc['customScript'] = new_script
  @_custom_script_dirty = true
end

#dirty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ecoportal/api/graphql/base/force.rb', line 40

def dirty?
  @_custom_script_dirty || pending_commands.any?
end

#pending_commandsObject

All pending commands for this force (editForce if script changed + binding ops).



50
51
52
# File 'lib/ecoportal/api/graphql/base/force.rb', line 50

def pending_commands
  @pending_commands ||= []
end

#queue_command(command_hash) ⇒ Object

Accumulate workflow commands (editForce, addBinding, removeBinding).



45
46
47
# File 'lib/ecoportal/api/graphql/base/force.rb', line 45

def queue_command(command_hash)
  pending_commands << command_hash
end