Class: Rack::TimeTraveler
- Inherits:
-
Object
- Object
- Rack::TimeTraveler
- Defined in:
- lib/rack/timetraveler.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ TimeTraveler
constructor
A new instance of TimeTraveler.
Constructor Details
#initialize(app, options = {}) ⇒ TimeTraveler
Returns a new instance of TimeTraveler.
7 8 9 10 11 12 13 14 |
# File 'lib/rack/timetraveler.rb', line 7 def initialize(app, = {}) @app, @options = app, default_fetcher = lambda { |env| fetch_from_env(env) } @options[:timestamp_fetcher] ||= default_fetcher @options[:enabled_environments] ||= [:development, :test] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/rack/timetraveler.rb', line 5 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rack/timetraveler.rb', line 5 def @options end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/timetraveler.rb', line 16 def call(env) return @app.call(env) unless enabled? time = (env) return @app.call(env) if time.nil? Timecop.travel(time) { @app.call(env) } end |