Class: Rack::TimeTraveler

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/timetraveler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @app, @options = app, options

  default_fetcher = lambda { |env| fetch_from_env(env) }
  @options[:timestamp_fetcher] ||= default_fetcher

  @options[:enabled_environments] ||= [:development, :test]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/rack/timetraveler.rb', line 5

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/rack/timetraveler.rb', line 5

def options
  @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 = validate_timestamp(env)

  return @app.call(env) if time.nil?

  Timecop.travel(time) { @app.call(env) }
end