Class: Serf::Middleware::ParcelMasher

Inherits:
Object
  • Object
show all
Defined in:
lib/serf/middleware/parcel_masher.rb

Overview

Middleware to coerce the parcel to Hashie::Mash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ ParcelMasher

Returns a new instance of ParcelMasher.

Parameters:

  • app

    the app



17
18
19
20
21
# File 'lib/serf/middleware/parcel_masher.rb', line 17

def initialize(app, *args)
  opts = Optser.extract_options! args
  @app = app
  @masher_class = opts.get :masher_class, Hashie::Mash
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/serf/middleware/parcel_masher.rb', line 11

def app
  @app
end

#masher_classObject (readonly)

Returns the value of attribute masher_class.



12
13
14
# File 'lib/serf/middleware/parcel_masher.rb', line 12

def masher_class
  @masher_class
end

Instance Method Details

#call(parcel) ⇒ Object

Coerces the parcel into a Hashie::Mash, makes sure that the message field is set, and then passes it along the chain.



26
27
28
29
30
# File 'lib/serf/middleware/parcel_masher.rb', line 26

def call(parcel)
  mashed_parcel = masher_class.new parcel
  mashed_parcel[:message] ||= {}
  app.call mashed_parcel
end