Class: SmartTodo::Dispatchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_todo/dispatchers/base.rb

Direct Known Subclasses

Output, Slack

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_message, todo_node, file, options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • event_message (String)

    the success message associated a specific event

  • todo_node (SmartTodo::Parser::TodoNode)
  • file (String)

    the file containing the TODO

  • options (Hash)


38
39
40
41
42
43
44
# File 'lib/smart_todo/dispatchers/base.rb', line 38

def initialize(event_message, todo_node, file, options)
  @event_message = event_message
  @todo_node = todo_node
  @options = options
  @file = file
  @assignees = @todo_node.assignees
end

Class Method Details

.class_for(dispatcher) ⇒ Class

Factory pattern to retrieve the right dispatcher class.

Parameters:

  • dispatcher (String)

Returns:

  • (Class)


12
13
14
15
16
17
18
19
# File 'lib/smart_todo/dispatchers/base.rb', line 12

def class_for(dispatcher)
  case dispatcher
  when "slack"
    Slack
  when nil, "output"
    Output
  end
end

.validate_options!(_options) ⇒ Object

Subclasses should define what options from the CLI they need in order to properly deliver the message. For instance the Slack dispatcher requires an API key.

Parameters:

  • _options (Hash)

Returns:

  • void

Raises:

  • (NotImplemetedError)


28
29
30
# File 'lib/smart_todo/dispatchers/base.rb', line 28

def validate_options!(_options)
  raise(NotImplemetedError, "subclass responsability")
end

Instance Method Details

#dispatchObject

This method gets called when a TODO reminder is expired and needs to be delivered. Dispatchers should implement this method to deliver the message where they need.

Returns:

  • void

Raises:

  • (NotImplemetedError)


50
51
52
# File 'lib/smart_todo/dispatchers/base.rb', line 50

def dispatch
  raise(NotImplemetedError, "subclass responsability")
end