Class: Shoryuken::BodyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/body_parser.rb

Class Method Summary collapse

Class Method Details

.parse(worker_class, sqs_msg) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shoryuken/body_parser.rb', line 4

def parse(worker_class, sqs_msg)
  body_parser = worker_class.get_shoryuken_options['body_parser']

  case body_parser
  when :json
    JSON.parse(sqs_msg.body)
  when Proc
    body_parser.call(sqs_msg)
  when :text, nil
    sqs_msg.body
  else
    if body_parser.respond_to?(:parse)
      # JSON.parse
      body_parser.parse(sqs_msg.body)
    elsif body_parser.respond_to?(:load)
      # see https://github.com/phstc/shoryuken/pull/91
      # JSON.load
      body_parser.load(sqs_msg.body)
    end
  end
end