Class: Rack::CanIUse
- Inherits:
-
Object
- Object
- Rack::CanIUse
- Defined in:
- lib/rack/caniuse.rb
Constant Summary collapse
- DefaultOptions =
{ features: [], redirect: 'http://browsehappy.com/' }
- Base =
::File.join(::File.dirname(__FILE__), '..', '..')
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ CanIUse
constructor
A new instance of CanIUse.
Constructor Details
#initialize(app, options = {}) ⇒ CanIUse
Returns a new instance of CanIUse.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/caniuse.rb', line 15 def initialize(app, = {}) .reverse_merge!(DefaultOptions) @app, @options, @features = app, , {} [:features].each do |feature| path = ::File.join(Base, 'caniuse', 'features-json', feature + '.json') unless ::File.readable?(path) raise "Invalid feature #{feature}." end hash = JSON.parse(::File.read(path)) @features[feature] = hash end end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rack/caniuse.rb', line 32 def call(env) agent = env['HTTP_USER_AGENT'] browser = Browser.new(ua: agent, accept_language: 'en-us') validate_support(browser) @app.call(env) end |