Class: Hecks::Bluebook::Mutation

Inherits:
Struct
  • Object
show all
Includes:
Behaviour::Mutation, IR
Defined in:
lib/hecks/bluebook/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Behaviour::Mutation

#appended_fields, #classified_source

Methods included from IR

extended, included

Instance Attribute Details

#opObject

Returns the value of attribute op

Returns:

  • (Object)

    the current value of op



8
9
10
# File 'lib/hecks/bluebook/command.rb', line 8

def op
  @op
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



8
9
10
# File 'lib/hecks/bluebook/command.rb', line 8

def source
  @source
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



8
9
10
# File 'lib/hecks/bluebook/command.rb', line 8

def target
  @target
end

Class Method Details

.sign_for(op) ⇒ Object

sign: — item #5 of the whole-project table-unification survey. increment/decrement's own +1/-1 used to be re-derived from the op NAME by two independent Rust codegen scripts (rust/project/ mutations.rb, rust/codegen/src/mutations.rs — a ternary on op == "increment" in each), even though the fact was already table-driven on the Ruby runtime side (Runtime::CommandRules::Arithmetic::MUTATION_OPS, held equal to Vocabulary::MutationOp by spec/vocabulary_conformance_spec.rb). Reads Vocabulary::MutationOp directly (plain data, no framework dependency — safe during parsing, same reason RuleReference's own bootstrap concerns don't apply here) rather than requiring Runtime::CommandRules from the bluebook/IR layer, which would be a real layering inversion (runtime depends on bluebook, not the reverse). "" (not nil) for ops with no sign, matching every other optional IR text field's own absent-is-empty-string convention.



27
28
29
# File 'lib/hecks/bluebook/command.rb', line 27

def self.sign_for(op)
  Hecks::Vocabulary.rows("MutationOp").find { |row| row["name"] == op.to_s }&.fetch("sign", "") || ""
end

Instance Method Details

#to_hObject

THE ONE GENUINELY BRANCHING EMISSION in the model: an append (or a DELEGATE — CommandBuilder#delegates_to's own comment gives the full reasoning for reusing this exact wire shape rather than inventing a parallel one) binds several fields at once and carries fields:, everything else carries a single source:. Declared emission covers the fixed head; super supplies it and this adds the tail, which is why a construct with a variable shape needs no new mixin API.



41
42
43
44
45
# File 'lib/hecks/bluebook/command.rb', line 41

def to_h
  return super.merge(fields: appended_fields) if [:append, :delegate].include?(op)

  super.merge(source: classified_source)
end