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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#afterObject

Returns the value of attribute after

Returns:

  • (Object)

    the current value of after



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def after
  @after
end

#attributeObject

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def attribute
  @attribute
end

#beforeObject

Returns the value of attribute before

Returns:

  • (Object)

    the current value of before



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def before
  @before
end

#by_typeObject

Returns the value of attribute by_type

Returns:

  • (Object)

    the current value of by_type



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def by_type
  @by_type
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def id
  @id
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def kind
  @kind
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def label
  @label
end

#opObject

Returns the value of attribute op

Returns:

  • (Object)

    the current value of op



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def op
  @op
end

#owner_idObject

Returns the value of attribute owner_id

Returns:

  • (Object)

    the current value of owner_id



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def owner_id
  @owner_id
end

#parent_idObject

Returns the value of attribute parent_id

Returns:

  • (Object)

    the current value of parent_id



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def parent_id
  @parent_id
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



26
27
28
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 26

def path
  @path
end

Instance Method Details

#descriptionObject

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



37
38
39
40
41
42
43
44
# File 'lib/ecoportal/api/graphql/diff/change.rb', line 37

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_hObject



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

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
  }.compact
end