Class: SolidFlow::Wait::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_flow/wait.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



33
34
35
# File 'lib/solid_flow/wait.rb', line 33

def initialize
  @instructions = []
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



31
32
33
# File 'lib/solid_flow/wait.rb', line 31

def instructions
  @instructions
end

Instance Method Details

#for(seconds: nil, timestamp: nil, at: nil, metadata: {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/solid_flow/wait.rb', line 37

def for(seconds: nil, timestamp: nil, at: nil, metadata: {})
   =
    case 
    when Hash
      .deep_dup
    else
      
    end
  options = { metadata:  }
  if seconds
    raise ArgumentError, "seconds must be positive" unless seconds.to_f.positive?

    options[:delay_seconds] = seconds.to_f
  elsif at || timestamp
    target = at || timestamp
    options[:run_at] = target
  else
    raise ArgumentError, "wait.for requires :seconds or :timestamp"
  end

  instruction = TimerInstruction.new(options)
  @instructions << instruction
  instruction
end

#for_signal(name, metadata: {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/solid_flow/wait.rb', line 62

def for_signal(name, metadata: {})
   =
    case 
    when Hash
      .deep_dup
    else
      
    end
  instruction = SignalInstruction.new(signal: name.to_sym, metadata: )
  @instructions << instruction
  instruction
end