Class: DAF::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/daf/command.rb

Overview

Represents a pair of Action and Monitor objects when requested, will begin watching the Monitor and when it triggers will invoke the action by default Command continues monitoring forever though subclasses may override this behavior

Instance Method Summary collapse

Constructor Details

#initialize(datasource) ⇒ Command

Create a new command object from a data source command object

Parameters:



15
16
17
# File 'lib/daf/command.rb', line 15

def initialize(datasource)
  @datasource = datasource
end

Instance Method Details

#cancelObject



33
34
35
# File 'lib/daf/command.rb', line 33

def cancel
  @thread.kill
end

#executeObject

Begins executing the command by starting the monitor specified in the data source - will return immediately



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/daf/command.rb', line 21

def execute
  @thread = Thread.new do
    if Thread.current != Thread.main
      loop do
        @datasource.monitor.on_trigger do
          @datasource.action.activate(@datasource.action_options)
        end
      end
    end
  end
end