Class: Serf::Middleware::ParcelMasher
- Inherits:
-
Object
- Object
- Serf::Middleware::ParcelMasher
- Defined in:
- lib/serf/middleware/parcel_masher.rb
Overview
Middleware to coerce the parcel to Hashie::Mash.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#masher_class ⇒ Object
readonly
Returns the value of attribute masher_class.
Instance Method Summary collapse
-
#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.
-
#initialize(app, *args) ⇒ ParcelMasher
constructor
A new instance of ParcelMasher.
Constructor Details
#initialize(app, *args) ⇒ ParcelMasher
Returns a new instance of ParcelMasher.
17 18 19 20 21 |
# File 'lib/serf/middleware/parcel_masher.rb', line 17 def initialize(app, *args) opts = Optser. args @app = app @masher_class = opts.get :masher_class, Hashie::Mash end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/serf/middleware/parcel_masher.rb', line 11 def app @app end |
#masher_class ⇒ Object (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 |