Class: WURFL::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/wurfl-lite-middleware.rb,
lib/wurfl-lite-middleware/version.rb

Constant Summary collapse

VERSION =
"1.0.7"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
9
10
11
12
13
14
15
# File 'lib/wurfl-lite-middleware.rb', line 6

def initialize( app, options = {} )
  @app = app

  # Try to get the location from either parameters or environment
  location = options.delete(:wurfl_xml) || ENV['WURFL_XML']
  @wurfl = location.nil? ? WURFL.new : WURFL.new( location )

  # Configure the object
  @wurfl.match_threshold = options[:match_threshold] if options[:match_threshold] 
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
# File 'lib/wurfl-lite-middleware.rb', line 16

def call( env )
  env['WURFL'] = @wurfl[ env[ 'HTTP_USER_AGENT' ] ]
  @app.call( env )
end