Class: Ductr::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/ductr/trigger.rb

Overview

The base class for any trigger, can be initialized by passing it its adapter name if any. A trigger must implement the #add method which is called for each trigger declaration. Depending on what your trigger do, you may have to implement the #start and #stop methods. #start is called when the scheduler relying on the trigger is started. #stop does the opposite: it is called when the scheduler relying on the trigger is stopped.

Direct Known Subclasses

RufusTrigger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter = nil) ⇒ Trigger

Creates a new trigger instance, called by the scheduler.

Parameters:

  • adapter (Adapter, Nil) (defaults to: nil)

    The trigger’s adapter, if any



19
20
21
# File 'lib/ductr/trigger.rb', line 19

def initialize(adapter = nil)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/ductr/trigger.rb', line 12

def adapter
  @adapter
end

Instance Method Details

#add(_method, _options) ⇒ void

This method returns an undefined value.

Adds a new trigger, called by a scheduler when a trigger is declared.

Parameters:

  • _method (Method)

    The scheduler method to be called by the trigger

  • _options (Hash<Symbol: Object>)

    options The options of the trigger declaration

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/ductr/trigger.rb', line 31

def add(_method, _options)
  raise NotImplementedError, "A trigger must implement the #add method"
end

#startvoid

This method returns an undefined value.

Called when the scheduler relying on the trigger is started.



40
# File 'lib/ductr/trigger.rb', line 40

def start; end

#stopvoid

This method returns an undefined value.

Called when the scheduler relying on the trigger is stopped.



47
# File 'lib/ductr/trigger.rb', line 47

def stop; end