Class: Serf::Middleware::UuidTagger
- Inherits:
-
Object
- Object
- Serf::Middleware::UuidTagger
- Defined in:
- lib/serf/middleware/uuid_tagger.rb
Overview
Middleware to add the uuid to the parcel hash if not already present.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#uuidable ⇒ Object
readonly
Returns the value of attribute uuidable.
Instance Method Summary collapse
- #call(parcel) ⇒ Object
-
#initialize(app, *args) ⇒ UuidTagger
constructor
A new instance of UuidTagger.
Constructor Details
#initialize(app, *args) ⇒ UuidTagger
Returns a new instance of UuidTagger.
19 20 21 22 23 |
# File 'lib/serf/middleware/uuid_tagger.rb', line 19 def initialize(app, *args) opts = Optser. args @app = app @uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new } end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
13 14 15 |
# File 'lib/serf/middleware/uuid_tagger.rb', line 13 def app @app end |
#uuidable ⇒ Object (readonly)
Returns the value of attribute uuidable.
14 15 16 |
# File 'lib/serf/middleware/uuid_tagger.rb', line 14 def uuidable @uuidable end |
Instance Method Details
#call(parcel) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/serf/middleware/uuid_tagger.rb', line 25 def call(parcel) # Duplicate the parcel parcel = parcel.dup # Tag with a UUID unless it already has one parcel[:uuid] ||= uuidable.create_coded_uuid # Pass on the given parcel with the uuid app.call parcel end |