Class: Serf::Middleware::UuidTagger

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ UuidTagger

Returns a new instance of UuidTagger.

Parameters:

  • app

    the app



19
20
21
22
23
# File 'lib/serf/middleware/uuid_tagger.rb', line 19

def initialize(app, *args)
  opts = Optser.extract_options! args
  @app = app
  @uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new }
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/serf/middleware/uuid_tagger.rb', line 13

def app
  @app
end

#uuidableObject (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