Class: GraphAgent::Channels::LastValue
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- GraphAgent::Channels::LastValue
- Defined in:
- lib/graph_agent/channels/last_value.rb
Constant Summary
Constants inherited from BaseChannel
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
- #available? ⇒ Boolean
- #checkpoint ⇒ Object
- #copy ⇒ Object
- #from_checkpoint(checkpoint) ⇒ Object
- #get ⇒ Object
-
#initialize(key: "", default: MISSING) ⇒ LastValue
constructor
A new instance of LastValue.
- #update(values) ⇒ Object
Methods inherited from BaseChannel
Constructor Details
Instance Method Details
#available? ⇒ Boolean
28 29 30 |
# File 'lib/graph_agent/channels/last_value.rb', line 28 def available? !@value.equal?(MISSING) end |
#checkpoint ⇒ Object
32 33 34 |
# File 'lib/graph_agent/channels/last_value.rb', line 32 def checkpoint @value end |
#copy ⇒ Object
42 43 44 45 46 |
# File 'lib/graph_agent/channels/last_value.rb', line 42 def copy ch = self.class.new(key: key) ch.instance_variable_set(:@value, @value) ch end |
#from_checkpoint(checkpoint) ⇒ Object
36 37 38 39 40 |
# File 'lib/graph_agent/channels/last_value.rb', line 36 def from_checkpoint(checkpoint) ch = self.class.new(key: key) ch.instance_variable_set(:@value, checkpoint.equal?(MISSING) ? MISSING : checkpoint) ch end |
#get ⇒ Object
11 12 13 14 15 |
# File 'lib/graph_agent/channels/last_value.rb', line 11 def get raise EmptyChannelError.new("Channel '#{key}' is empty") if @value.equal?(MISSING) @value end |
#update(values) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graph_agent/channels/last_value.rb', line 17 def update(values) return false if values.empty? if values.length != 1 raise InvalidUpdateError.new("At key '#{key}': Can receive only one value per step.") end @value = values.last true end |