Class: Rack::TimeZoneMiddleware
- Inherits:
-
Object
- Object
- Rack::TimeZoneMiddleware
- Defined in:
- lib/rack/time-zone-middleware.rb,
lib/rack/time-zone-middleware/version.rb
Constant Summary collapse
- DEFAULT_TIME_ZONE =
'Europe/Moscow'
- DEFAULT_AS_TIME_ZONE =
'Moscow'
- DEFAULT_KEY =
'dummy.time_zone'
- DEFAULT_COOKIE_KEY =
DEFAULT_KEY
- MAP_WARNING =
"Please install `activesupport` gem and `require 'active_support/values/time_zone'` or provide custom TimeZone map, as a `Hash` like `{'Moscow' => 'Europe/Moscow'}`"
- VERSION =
'0.1.4'
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #find_as_time_zone(name) ⇒ Object
-
#initialize(app, opts = {}, &block) ⇒ TimeZoneMiddleware
constructor
A new instance of TimeZoneMiddleware.
Constructor Details
#initialize(app, opts = {}, &block) ⇒ TimeZoneMiddleware
Returns a new instance of TimeZoneMiddleware.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/time-zone-middleware.rb', line 14 def initialize(app, opts = {}, &block) @app = app @options = {} [:default_tz] = opts.fetch(:default_tz, DEFAULT_TIME_ZONE) [:default_as_tz] = opts.fetch(:default_as_tz, DEFAULT_AS_TIME_ZONE) [:time_zone_key] = opts.fetch(:time_zone_key, DEFAULT_KEY) [:cookie_key] = opts.fetch(:cookie_key, DEFAULT_COOKIE_KEY) @time_zone_map = opts.fetch(:time_zone_map, nil) || default_time_zone_map if block_given? @runner = block else @runner = ->(mw, env) { _call(mw, env) } end end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
12 13 14 |
# File 'lib/rack/time-zone-middleware.rb', line 12 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/rack/time-zone-middleware.rb', line 12 def @options end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
12 13 14 |
# File 'lib/rack/time-zone-middleware.rb', line 12 def runner @runner end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 |
# File 'lib/rack/time-zone-middleware.rb', line 32 def call(env) runner.call(self, env) end |
#find_as_time_zone(name) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rack/time-zone-middleware.rb', line 36 def find_as_time_zone(name) zone_name, _ = time_zone_map.detect { |_, v| v.eql? name } zone_name || [:default_as_tz] rescue [:default_as_tz] end |