Module: Messed::Controller::Respond

Included in:
Messed
Defined in:
lib/messed/controller/respond.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(c) ⇒ Object



5
6
7
8
9
# File 'lib/messed/controller/respond.rb', line 5

def self.included(c)
  c.instance_eval "
    after_processing :clear_responses
  "
end

Instance Method Details

#clear_responsesObject



15
16
17
# File 'lib/messed/controller/respond.rb', line 15

def clear_responses
  responses.clear
end

#reply(response, options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/messed/controller/respond.rb', line 23

def reply(response, options = {})
  options[:to] ||= message.from
  options[:from] ||= message.to
  options[:in_reply_to] ||= message
  set_response(response, options)
end

#responsesObject



11
12
13
# File 'lib/messed/controller/respond.rb', line 11

def responses
  @response ||= []
end

#say(response) ⇒ Object



19
20
21
# File 'lib/messed/controller/respond.rb', line 19

def say(response)
  set_response(response)
end

#set_response(response, options = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/messed/controller/respond.rb', line 35

def set_response(response, options = nil)
  message = message_class.new
  message.body = response.is_a?(Message) ? response.body : response
  if options
    options.each do |key, value|
      message.send(:"#{key}=", value)
    end
  end
  self.responses << message
end

#whisper(response, options = {}) ⇒ Object



30
31
32
33
# File 'lib/messed/controller/respond.rb', line 30

def whisper(response, options = {})
  options[:private] = true
  reply(response, options)
end