Module: Jpmobile::RequestWithMobile

Included in:
Rack::Request
Defined in:
lib/jpmobile/request_with_mobile.rb

Instance Method Summary collapse

Instance Method Details

#mobileObject

携帯電話の機種に応じて Mobile::xxx を返す。 携帯電話でない場合はnilを返す。



41
42
43
# File 'lib/jpmobile/request_with_mobile.rb', line 41

def mobile
  env['rack.jpmobile']
end

#mobile?Boolean

携帯電話からであれば trueを、そうでなければ false を返す。

Returns:

  • (Boolean)


30
31
32
# File 'lib/jpmobile/request_with_mobile.rb', line 30

def mobile?
  mobile and not mobile.smart_phone?
end

#remote_addrObject

for reverse proxy.



14
15
16
17
18
19
20
21
22
# File 'lib/jpmobile/request_with_mobile.rb', line 14

def remote_addr
  if respond_to?(:remote_ip)
    return __send__(:remote_ip)  # for Rails
  elsif respond_to?(:ip)
    return __send__(:ip)         # for Rack
  else
    return ( env["HTTP_X_FORWARDED_FOR"] ? env["HTTP_X_FORWARDED_FOR"].split(',').pop : env["REMOTE_ADDR"] )
  end
end

#smart_phone?Boolean

viewの切り替えをするかどうか

Returns:

  • (Boolean)


35
36
37
# File 'lib/jpmobile/request_with_mobile.rb', line 35

def smart_phone?
  mobile and mobile.smart_phone?
end

#user_agentObject

環境変数 HTTP_USER_AGENT を返す。



9
10
11
# File 'lib/jpmobile/request_with_mobile.rb', line 9

def user_agent
  env['HTTP_USER_AGENT']
end

#user_agent=(str) ⇒ Object

環境変数 HTTP_USER_AGENT を設定する。



25
26
27
# File 'lib/jpmobile/request_with_mobile.rb', line 25

def user_agent=(str)
  self.env["HTTP_USER_AGENT"] = str
end