Class: Ecoportal::API::GraphQL::Model::Template::Option

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

Overview

One option of a Select field. Read-side field name is name (see the gem's own selectField fragment, fragment/pages/common_page_union.rb); write-side commands (addSelectFieldOption/editSelectFieldOption) name the same thing label — this class always uses label, mapping the read-side name -> label at load time (Read.call), so callers never see the read/write naming split.

Constant Summary collapse

PLACEHOLDER_PREFIX =
'opt'.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:, field:, id: nil, label: nil, value: nil, weight: nil) ⇒ Option

Returns a new instance of Option.



19
20
21
22
23
24
25
26
27
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 19

def initialize(template:, field:, id: nil, label: nil, value: nil, weight: nil)
  @template = template
  @field    = field
  @id       = id
  @label    = label
  @value    = value
  @weight   = weight
  @snapshot = snapshot_attrs.freeze
end

Instance Attribute Details

#field ⇒ Object (readonly)

Returns the value of attribute field.



16
17
18
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 16

def field
  @field
end

#label ⇒ Object

Returns the value of attribute label.



17
18
19
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 17

def label
  @label
end

#template ⇒ Object (readonly)

Returns the value of attribute template.



16
17
18
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 16

def template
  @template
end

#value ⇒ Object

Returns the value of attribute value.



17
18
19
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 17

def value
  @value
end

#weight ⇒ Object

Returns the value of attribute weight.



17
18
19
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 17

def weight
  @weight
end

Instance Method Details

#changed_attributes ⇒ Object



33
34
35
36
37
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 33

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/ecoportal/api/graphql/model/template/option.rb', line 29

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