Class: Macmillan::Utils::Middleware::Uuid
- Inherits:
-
Object
- Object
- Macmillan::Utils::Middleware::Uuid
- Defined in:
- lib/macmillan/utils/middleware/uuid.rb
Overview
Rack Middleware for uniquley identifying a user.
If the user is logged in, their UUID will be based upon their user_id, otherwise it will be randomly generated. This UUID will be stored in the rack env, and persisted in a cookie.
This middleware expects a user object to be stored in the rack env.
Defined Under Namespace
Classes: CallHandler
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Uuid
constructor
A new instance of Uuid.
- #process(env) ⇒ Object
Constructor Details
#initialize(app, opts = {}) ⇒ Uuid
Returns a new instance of Uuid.
18 19 20 21 22 |
# File 'lib/macmillan/utils/middleware/uuid.rb', line 18 def initialize(app, opts = {}) @app = app @user_env_key = opts[:user_env_key] || 'current_user' @user_id_method = opts[:user_id_method] || 'user_id' end |
Class Method Details
.env_key ⇒ Object
14 15 16 |
# File 'lib/macmillan/utils/middleware/uuid.rb', line 14 def self.env_key 'user.uuid' end |
Instance Method Details
#call(env) ⇒ Object
88 89 90 |
# File 'lib/macmillan/utils/middleware/uuid.rb', line 88 def call(env) dup.process(env) end |
#process(env) ⇒ Object
92 93 94 95 |
# File 'lib/macmillan/utils/middleware/uuid.rb', line 92 def process(env) handler = CallHandler.new(env, @app, @user_env_key, @user_id_method, self.class.env_key) handler.finish end |