Class: GlassOctopus::Middleware::JsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/glass_octopus/middleware/json_parser.rb

Defined Under Namespace

Classes: ContextWithJsonParsedMessage

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ JsonParser

Returns a new instance of JsonParser.



7
8
9
10
11
12
# File 'lib/glass_octopus/middleware/json_parser.rb', line 7

def initialize(app, options={})
  @app = app
  @klass = options.delete(:class)
  @encoding = options.delete(:encoding)
  @options = options
end

Instance Method Details

#call(ctx) ⇒ Object



14
15
16
17
18
# File 'lib/glass_octopus/middleware/json_parser.rb', line 14

def call(ctx)
  message = parse(ensure_encoding(ctx.message.value))
  ctx = ContextWithJsonParsedMessage.new(ctx, message)
  @app.call(ctx)
end