Module: Jpmobile::RequestWithMobile
- Included in:
- Rack::Request
- Defined in:
- lib/jpmobile/request_with_mobile.rb
Instance Method Summary collapse
-
#mobile ⇒ Object
携帯電話の機種に応じて Mobile::xxx を返す。 携帯電話でない場合はnilを返す。.
-
#mobile? ⇒ Boolean
携帯電話からであれば
true
を、そうでなければfalse
を返す。. -
#remote_addr ⇒ Object
for reverse proxy.
-
#smart_phone? ⇒ Boolean
スマートフォンであれば
true
を、そうでなければfalse
を返す。. -
#tablet? ⇒ Boolean
タブレットからであれば
true
を、そうでなければfalse
を返す. -
#user_agent ⇒ Object
環境変数 HTTP_USER_AGENT を返す。.
-
#user_agent=(str) ⇒ Object
環境変数 HTTP_USER_AGENT を設定する。.
Instance Method Details
#mobile ⇒ Object
携帯電話の機種に応じて Mobile::xxx を返す。携帯電話でない場合はnilを返す。
49 50 51 |
# File 'lib/jpmobile/request_with_mobile.rb', line 49 def mobile env['rack.jpmobile'] end |
#mobile? ⇒ Boolean
携帯電話からであれば true
を、そうでなければ false
を返す。
33 34 35 |
# File 'lib/jpmobile/request_with_mobile.rb', line 33 def mobile? mobile and !mobile.smart_phone? end |
#remote_addr ⇒ Object
for reverse proxy.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jpmobile/request_with_mobile.rb', line 13 def remote_addr if respond_to?(:remote_ip) __send__(:remote_ip) # for Rails elsif respond_to?(:ip) __send__(:ip) # for Rack else if env['HTTP_X_FORWARDED_FOR'] env['HTTP_X_FORWARDED_FOR'].split(',').pop else env['REMOTE_ADDR'] end end end |
#smart_phone? ⇒ Boolean
スマートフォンであれば true
を、そうでなければ false
を返す。
38 39 40 |
# File 'lib/jpmobile/request_with_mobile.rb', line 38 def smart_phone? mobile and mobile.smart_phone? end |
#tablet? ⇒ Boolean
タブレットからであれば true
を、そうでなければ false
を返す
43 44 45 |
# File 'lib/jpmobile/request_with_mobile.rb', line 43 def tablet? mobile and mobile.tablet? end |
#user_agent ⇒ Object
環境変数 HTTP_USER_AGENT を返す。
8 9 10 |
# File 'lib/jpmobile/request_with_mobile.rb', line 8 def user_agent env['HTTP_USER_AGENT'] end |
#user_agent=(str) ⇒ Object
環境変数 HTTP_USER_AGENT を設定する。
28 29 30 |
# File 'lib/jpmobile/request_with_mobile.rb', line 28 def user_agent=(str) self.env['HTTP_USER_AGENT'] = str end |