Class: ExcADG::VStateData::Full

Inherits:
Key
  • Object
show all
Defined in:
lib/excadg/vstate_data.rb

Overview

contains actual data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Key

#<=>, #eql?

Constructor Details

#initialize(state:, data:, name:, vertex: nil) ⇒ Full

param state: Symbol, one of StateMachine.GRAPH.vertices param data: all data returned by a Vertice’s Payload param name: Symboli -c name of the associated Vertex param vertex: Vertex that produced the data



53
54
55
56
57
58
# File 'lib/excadg/vstate_data.rb', line 53

def initialize state:, data:, name:, vertex: nil
  # observation: Ractor.current returns Vertex object if invoked from a Vertex
  super(name:, vertex: vertex || Ractor.current)
  @state = state
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args, &_block) ⇒ Object

auto-generated methods to check states easier; note: define_method causes these object to become un-shareable what breaks Broker’s messaging

Raises:

  • (NoMethodError)


81
82
83
84
85
# File 'lib/excadg/vstate_data.rb', line 81

def method_missing(method, *_args, &_block)
  raise NoMethodError unless respond_to_missing? method, _args

  @state.eql? method[...-1].to_sym
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



47
48
49
# File 'lib/excadg/vstate_data.rb', line 47

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



47
48
49
# File 'lib/excadg/vstate_data.rb', line 47

def name
  @name
end

#stateObject (readonly)

Returns the value of attribute state.



47
48
49
# File 'lib/excadg/vstate_data.rb', line 47

def state
  @state
end

#vertexObject (readonly)

Returns the value of attribute vertex.



47
48
49
# File 'lib/excadg/vstate_data.rb', line 47

def vertex
  @vertex
end

Instance Method Details

#respond_to_missing?(method, *_args) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/excadg/vstate_data.rb', line 87

def respond_to_missing? method, *_args
  method.to_s.end_with?('?') && ExcADG::StateMachine::GRAPH.has_vertex?(method[...-1].to_sym)
end

#to_json(*args) ⇒ Object

method omits objects without a good known text representation



65
66
67
68
69
70
71
# File 'lib/excadg/vstate_data.rb', line 65

def to_json(*args)
  {
    name: @name,
    state: @state,
    data: @data
  }.to_json(*args)
end

#to_keyObject

converts full object to key to use in Hash



74
75
76
# File 'lib/excadg/vstate_data.rb', line 74

def to_key
  Key.new vertex: @vertex, name: @name
end

#to_sObject



60
61
62
# File 'lib/excadg/vstate_data.rb', line 60

def to_s
  "#{name || vertex} (#{state})"
end