Method: Ronin::Web::Server::Conditions::ClassMethods#device_type

Defined in:
lib/ronin/web/server/conditions.rb

#device_type(matcher) ⇒ Object (protected)

Condition to match the device type of the User-Agent header of the request.

Array of device type Symbols, the exact devicde type Symbol, Proc, or any other object which defines an #=== method.

Examples:

Match a specific device type:

get '/path', device_type: :crawler do
  halt 404
end

Match multiple device types:

get '/path', device_type: [:smartphone, :appliance] do
  # ...
end

Parameters:

API:

  • semipublic



324
325
326
327
328
329
330
331
332
333
# File 'lib/ronin/web/server/conditions.rb', line 324

def device_type(matcher)
  condition do
    if (device_type = request.device_type)
      case matcher
      when Array then matcher.include?(device_type)
      else            matcher === device_type
      end
    end
  end
end