Class: Ecoportal::API::GraphQL::Diff::Change

Inherits:
Struct
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/diff/change.rb

Overview

One structural change between two snapshots of the same page/template.

Deliberately command-ready: op + kind + id + before/after is enough for a later pass to synthesise the matching WorkflowCommand (editStage / addField / removeField / editFieldConfiguration / addSelectFieldOption / …) — the "portable commit".

op: :added | :removed | :changed | :moved kind: :stage | :section | :field | :option | :field_config | :gauge_stop

parent_id: id of the owning entity when the change is nested and the child id alone is not enough to address a command. Set for :option changes (the parent data field id) so a synthesiser can emit add/edit/removeSelectFieldOption without re-deriving it; also for :field_config (the data field id) and :gauge_stop (the gauge field id).

by_type: for :field_config changes, the byType sub-hash key (e.g. :gauge, :select, :date) under which the typed editFieldConfiguration property is nested. nil for other kinds.

owner_id: the id of the GRANDPARENT node, when a create needs a second structural back-ref that parent_id alone cannot carry. Set for an ADDED :field (parent_id = its section id, owner_id = its stage id) because addField requires BOTH sectionId and stageId (both NON_NULL in the schema). nil for every other kind/op.

value: for an ADDED :option, the select option's value (the schema's addSelectFieldOption requires it — see AddSelectFieldOptionInput, backend authority). Read from the source doc's option.value (VersionDiff#index_options); nil when the source doc did not carry one. NEVER defaulted to label/weight by the synthesiser — see CommandSynthesizer#option_command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#after ⇒ Object

Returns the value of attribute after

Returns:

  • (Object) —

    the current value of after



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def after
  @after
end

#attribute ⇒ Object

Returns the value of attribute attribute

Returns:

  • (Object) —

    the current value of attribute



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def attribute
  @attribute
end

#before ⇒ Object

Returns the value of attribute before

Returns:

  • (Object) —

    the current value of before



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def before
  @before
end

#by_type ⇒ Object

Returns the value of attribute by_type

Returns:

  • (Object) —

    the current value of by_type



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def by_type
  @by_type
end

#id ⇒ Object

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def id
  @id
end

#kind ⇒ Object

Returns the value of attribute kind

Returns:

  • (Object) —

    the current value of kind



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def kind
  @kind
end

#label ⇒ Object

Returns the value of attribute label

Returns:

  • (Object) —

    the current value of label



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def label
  @label
end

#op ⇒ Object

Returns the value of attribute op

Returns:

  • (Object) —

    the current value of op



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def op
  @op
end

#owner_id ⇒ Object

Returns the value of attribute owner_id

Returns:

  • (Object) —

    the current value of owner_id



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def owner_id
  @owner_id
end

#parent_id ⇒ Object

Returns the value of attribute parent_id

Returns:

  • (Object) —

    the current value of parent_id



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def parent_id
  @parent_id
end

#path ⇒ Object

Returns the value of attribute path

Returns:

  • (Object) —

    the current value of path



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def path
  @path
end

#value ⇒ Object

Returns the value of attribute value

Returns:

  • (Object) —

    the current value of value



31
32
33
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 31

def value
  @value
end

Instance Method Details

#description ⇒ Object

One-line human description for a changelog / ticket comment.



42
43
44
45
46
47
48
49
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 42

def description
  case op
  when :added   then "+ #{kind} '#{label}' added#{at_path}"
  when :removed then "- #{kind} '#{label}' removed#{at_path}"
  when :changed then "~ #{kind} '#{label}' #{attribute}: #{fmt(before)} -> #{fmt(after)}#{at_path}"
  when :moved   then "> #{kind} '#{label}' moved: #{fmt(before)} -> #{fmt(after)}"
  end
end

#to_h ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 33

def to_h
  {
    op: op, kind: kind, id: id, label: label, path: path,
    attribute: attribute, before: before, after: after, parent_id: parent_id,
    by_type: by_type, owner_id: owner_id, value: value
  }.compact
end