Module: Jpmobile::RequestWithMobile

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) mobile

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



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

def mobile
  env['rack.jpmobile']
end

- (Boolean) mobile?

携帯電話からであれば 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

- (Object) remote_addr

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

- (Boolean) smart_phone?

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

Returns:

  • (Boolean)


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

def smart_phone?
  mobile and mobile.smart_phone?
end

- (Object) user_agent

環境変数 HTTP_USER_AGENT を返す。



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

def user_agent
  env['HTTP_USER_AGENT']
end

- (Object) user_agent=(str)

環境変数 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