Class: Trailblazer::Activity::DSL::Linear::State

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/activity/dsl/linear/state.rb

Overview

A State instance is kept per DSL client, which usually is a subclass of Path, Railway, etc. State doesn’t have any immutable features - all write operations to it must guarantee they only replace instance variables.

DISCUSS: why do we have this structure? It doesn’t cover “immutable copying”, that has to be done by its clients.

also, copy with to_h

Defined Under Namespace

Classes: Normalizer

Instance Method Summary collapse

Constructor Details

#initialize(normalizers:, initial_sequence:, fields: {}.freeze, **normalizer_options) ⇒ State

remembers how to call normalizers (e.g. track_color), TaskBuilder remembers sequence



16
17
18
19
20
21
# File 'lib/trailblazer/activity/dsl/linear/state.rb', line 16

def initialize(normalizers:, initial_sequence:, fields: {}.freeze, **normalizer_options)
  @normalizer         = normalizers # compiled normalizers.
  @sequence           = initial_sequence
  @normalizer_options = normalizer_options
  @fields             = fields
end

Instance Method Details

#copyObject

Called to “inherit” a state.



24
25
26
# File 'lib/trailblazer/activity/dsl/linear/state.rb', line 24

def copy
  self.class.new(normalizers: @normalizer, initial_sequence: @sequence, fields: @fields, **@normalizer_options)
end

#to_hObject



28
29
30
# File 'lib/trailblazer/activity/dsl/linear/state.rb', line 28

def to_h
  {sequence: @sequence, normalizers: @normalizer, normalizer_options: @normalizer_options, fields: @fields} # FIXME.
end

#update_options(fields) ⇒ Object



36
37
38
# File 'lib/trailblazer/activity/dsl/linear/state.rb', line 36

def update_options(fields)
  @fields = fields
end

#update_sequence(&block) ⇒ Object



32
33
34
# File 'lib/trailblazer/activity/dsl/linear/state.rb', line 32

def update_sequence(&block)
  @sequence = yield(to_h)
end