Module: Mobvious

Defined in:
lib/mobvious.rb,
lib/mobvious/config.rb,
lib/mobvious/version.rb,
lib/mobvious/manager.rb,
lib/mobvious/strategies/url.rb,
lib/mobvious/strategies/cookie.rb,
lib/mobvious/strategies/mobileesp.rb

Overview

A library (Rack middleware) to detect device types (mobile, tablet, desktop etc.) from requests.

See Manager for the actual Rack middleware.

See Config for configuration options (and set them via calling Mobvious.config).

See Strategies for predefined strategies or roll out your own.

Defined Under Namespace

Modules: Strategies Classes: Config, Manager

Constant Summary

VERSION =
"0.3.2"

Class Method Summary (collapse)

Class Method Details

+ (Object) config

An accessor for the global Mobvious configuration object. See Config for configuration options.



26
27
28
# File 'lib/mobvious.rb', line 26

def self.config
  @config ||= Mobvious::Config.new
end

+ (Object) configure {|Config| ... }

A configuration method, yields the Mobvious.config object.

Yields:

  • (Config)

    object holding Mobvious configuration



18
19
20
21
22
# File 'lib/mobvious.rb', line 18

def self.configure &block
  raise "Configure method needs to be passed a block." unless block_given?

  yield self.config
end

+ (Object) strategy(class_name)

An accessor for getting an instance of a strategy that is currently in use. (Must be present in current Mobvious.config.strategies.)



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mobvious.rb', line 33

def self.strategy(class_name)
  matching_strategies = self.config.strategies.select do
    |strategy| strategy.class.name.split('::').last == class_name
  end

  if matching_strategies.size == 1
    matching_strategies.first
  else
    matching_strategies
  end
end