Class: Ecoportal::API::GraphQL::Model::Template::Binding

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/ecoportal/api/graphql/model/template/binding.rb

Overview

A force binding — addBinding/editBinding's referenceId is the field (or field placeholder) the binding points at. reference_id= accepts either a raw id/String OR a Field (or any object answering #ref) so a caller can write binding.reference_id = some_field and let the SAME just-created-or-real-id resolution Field#ref already does apply here automatically — no separate "resolve the field id" step for the caller to remember.

Constant Summary collapse

PLACEHOLDER_PREFIX =
'bnd'.freeze
BINDING_TYPE =
'field'.freeze

Instance Attribute Summary collapse

Attributes included from Node

#id

Instance Method Summary collapse

Methods included from Node

#new?, #placeholder, #ref, #remove!, #removed?, #resolve!

Constructor Details

#initialize(template:, force:, id: nil, name: nil, reference_id: nil, type: BINDING_TYPE) ⇒ Binding



22
23
24
25
26
27
28
29
30
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 22

def initialize(template:, force:, id: nil, name: nil, reference_id: nil, type: BINDING_TYPE)
  @template     = template
  @force        = force
  @id           = id
  @name         = name
  @type         = type
  self.reference_id = reference_id
  @snapshot = snapshot_attrs.freeze
end

Instance Attribute Details

#force ⇒ Object (readonly)

Returns the value of attribute force.



19
20
21
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 19

def force
  @force
end

#name ⇒ Object

Returns the value of attribute name.



20
21
22
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 20

def name
  @name
end

#reference_id ⇒ Object

Resolved at read time: the referenced node's own #ref when it is one (a Field or anything else in this tree), otherwise the raw value as given.



36
37
38
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 36

def reference_id
  @reference_id.respond_to?(:ref) ? @reference_id.ref : @reference_id
end

#template ⇒ Object (readonly)

Returns the value of attribute template.



19
20
21
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 19

def template
  @template
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 19

def type
  @type
end

Instance Method Details

#changed_attributes ⇒ Object



44
45
46
47
48
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 44

def changed_attributes
  return {} if new? || removed?

  snapshot_attrs.each_with_object({}) { |(k, v), h| h[k] = v if v != @snapshot[k] }
end

#dirty? ⇒ Boolean



40
41
42
# File 'lib/ecoportal/api/graphql/model/template/binding.rb', line 40

def dirty?
  !removed? && !new? && snapshot_attrs != @snapshot
end