Class: OFlow::Actors::Trigger

Inherits:
OFlow::Actor show all
Defined in:
lib/oflow/actors/trigger.rb

Direct Known Subclasses

HttpServer

Instance Attribute Summary collapse

Attributes inherited from OFlow::Actor

#task

Instance Method Summary collapse

Methods inherited from OFlow::Actor

#busy?, #inputs, #options, #outputs, #perform, #set_option, #with_own_thread

Constructor Details

#initialize(task, options) ⇒ Trigger

Returns a new instance of Trigger.



15
16
17
18
19
# File 'lib/oflow/actors/trigger.rb', line 15

def initialize(task, options)
  super
  @count = 0
  set_options(options)
end

Instance Attribute Details

#countObject (readonly)

The number of time the timer has fired or shipped.



13
14
15
# File 'lib/oflow/actors/trigger.rb', line 13

def count
  @count
end

#labelObject (readonly)

Label for the Tracker is used and for trigger content.



8
9
10
# File 'lib/oflow/actors/trigger.rb', line 8

def label
  @label
end

#with_trackerObject (readonly)

Boolean flag indicating a tracker should be added to the trigger content if true.



11
12
13
# File 'lib/oflow/actors/trigger.rb', line 11

def with_tracker
  @with_tracker
end

Instance Method Details

#new_eventObject



21
22
23
24
# File 'lib/oflow/actors/trigger.rb', line 21

def new_event()
  tracker = @with_tracker ? Tracker.create(@label) : nil
  Box.new({ source: task.full_name, label: @label, timestamp: Time.now.utc() }, tracker)
end

#set_label(v) ⇒ Object



31
32
33
34
# File 'lib/oflow/actors/trigger.rb', line 31

def set_label(v)
  v = v.to_s unless v.nil?
  @label = v
end

#set_options(options) ⇒ Object



26
27
28
29
# File 'lib/oflow/actors/trigger.rb', line 26

def set_options(options)
  set_with_tracker(options[:with_tracker])
  @label = options[:label].to_s
end

#set_with_tracker(v) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/oflow/actors/trigger.rb', line 36

def set_with_tracker(v)
  v = false if v.nil?
  unless true == v || false == v
    raise ConfigError.new("Expected with_tracker to be a boolean, not a #{v.class}.")
  end
  @with_tracker = v
end