Class: Rack::Synctime
- Inherits:
-
Object
- Object
- Rack::Synctime
- Defined in:
- lib/rack/synctime.rb,
lib/rack/synctime/version.rb
Constant Summary collapse
- DEFAULT_HEADER_NAME =
"X-Synced-At"
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #call(env) ⇒ Object
- #current_time_with_offset ⇒ Object
-
#initialize(app, header_name = DEFAULT_HEADER_NAME, time_offset = 0) ⇒ Synctime
constructor
A new instance of Synctime.
Constructor Details
#initialize(app, header_name = DEFAULT_HEADER_NAME, time_offset = 0) ⇒ Synctime
Returns a new instance of Synctime.
7 8 9 10 11 |
# File 'lib/rack/synctime.rb', line 7 def initialize(app, header_name = DEFAULT_HEADER_NAME, time_offset = 0) @app = app @synced_at_header_name = header_name @time_offset = time_offset end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/rack/synctime.rb', line 13 def call(env) now = current_time_with_offset resp = @app.call(env) resp[1][@synced_at_header_name] = now.to_s resp end |
#current_time_with_offset ⇒ Object
20 21 22 |
# File 'lib/rack/synctime.rb', line 20 def current_time_with_offset Time.now.to_i + @time_offset end |