Class: Dialogue::ConversationTemplateRunner

Inherits:
Object
  • Object
show all
Includes:
ConversationOptions
Defined in:
lib/dialogue/conversation_template_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConversationOptions

#method_missing

Constructor Details

#initialize(message, options = {}) ⇒ ConversationTemplateRunner

Returns a new instance of ConversationTemplateRunner.



7
8
9
10
11
12
# File 'lib/dialogue/conversation_template_runner.rb', line 7

def initialize(message, options={})
  guard_options! options

  @message = message
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dialogue::ConversationOptions

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/dialogue/conversation_template_runner.rb', line 5

def message
  @message
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/dialogue/conversation_template_runner.rb', line 5

def options
  @options
end

Instance Method Details

#channel_idObject



14
15
16
# File 'lib/dialogue/conversation_template_runner.rb', line 14

def channel_id
  decorated_message.channel_id
end

#decorated_messageObject



18
19
20
# File 'lib/dialogue/conversation_template_runner.rb', line 18

def decorated_message
  @decorated_message ||= MessageDecorators::Slack.new(message)
end

#message_from_author?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dialogue/conversation_template_runner.rb', line 22

def message_from_author?
  user_id == options[:author_id]
end

#run(template) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dialogue/conversation_template_runner.rb', line 26

def run(template)
  unless message_from_author?
    if Dialogue.conversation_registered? user_id, channel_id
      conversation = Dialogue.find_conversation user_id, channel_id
    else
      conversation = Conversation.new template, decorated_message, options

      Dialogue.register_conversation conversation
    end

    conversation.perform decorated_message
  end
end

#user_idObject



40
41
42
# File 'lib/dialogue/conversation_template_runner.rb', line 40

def user_id
  decorated_message.user_id
end