class SmartTodo::Dispatchers::Base
Public Class Methods
Factory pattern to retrive the right dispatcher class.
@param dispatcher [String]
@return [Class]
# File lib/smart_todo/dispatchers/base.rb, line 11 def self.class_for(dispatcher) case dispatcher when "slack" Slack when nil, 'output' Output end end
@param event_message [String] the success message associated
a specific event
@param todo_node [SmartTodo::Parser::TodoNode] @param file [String] the file containing the TODO @param options [Hash]
# File lib/smart_todo/dispatchers/base.rb, line 36 def initialize(event_message, todo_node, file, options) @event_message = event_message @todo_node = todo_node @options = options @file = file @assignee = @todo_node.metadata.assignee end
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.
@param _options [Hash]
@return void
# File lib/smart_todo/dispatchers/base.rb, line 27 def self.validate_options!(_options) raise(NotImplemetedError, 'subclass responsability') end
Public Instance Methods
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.
@return void
# File lib/smart_todo/dispatchers/base.rb, line 48 def dispatch raise(NotImplemetedError, 'subclass responsability') end
Private Instance Methods
@param user [Hash]
# File lib/smart_todo/dispatchers/base.rb, line 87 def existing_user "Hello :wave:," end
Prepare the content of the message to send to the TODO assignee
@param user [Hash] contain information about a user @return [String]
# File lib/smart_todo/dispatchers/base.rb, line 58 def slack_message(user) header = if user.key?('fallback') unexisting_user else existing_user end <<~EOM #{header} You have an assigned TODO in the `#{@file}` file. #{@event_message} Here is the associated comment on your TODO: ``` #{@todo_node.comment.strip} ``` EOM end
Message in case a TODO's assignee doesn't exist in the Slack
organization
@return [String]
# File lib/smart_todo/dispatchers/base.rb, line 82 def unexisting_user "Hello :wave:,\n\n`#{@assignee}` had an assigned TODO but this user or channel doesn't exist on Slack anymore." end