Class: MobileEnhancements::RequestHelper
- Inherits:
-
Object
- Object
- MobileEnhancements::RequestHelper
- Extended by:
- Forwardable
- Defined in:
- lib/mobile_enhancements/request_helper.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
Instance Method Summary collapse
-
#desktop_path(path = request.path) ⇒ Object
strips any mobile prefix from the path.
-
#desktop_request? ⇒ Boolean
returns whether or not this is a desktop request.
-
#desktop_url(url = request.url) ⇒ Object
strips any mobile prefix from the url.
-
#determine_format ⇒ Object
returns what format should be used by the request.
-
#determine_layout ⇒ Object
returns a string defining which layout file to use.
-
#initialize(request, configuration) ⇒ RequestHelper
constructor
A new instance of RequestHelper.
-
#mobile_param_value ⇒ Object
returns what the value of the mobile parameter should be.
-
#mobile_path(path = request.path) ⇒ Object
ensures a mobile prefix exists in the path.
-
#mobile_request? ⇒ Boolean
returns whether or not this is a mobile request.
-
#mobile_url(url = request.url) ⇒ Object
ensures a mobile prefix exists in the url.
Constructor Details
#initialize(request, configuration) ⇒ RequestHelper
Returns a new instance of RequestHelper.
17 18 19 20 |
# File 'lib/mobile_enhancements/request_helper.rb', line 17 def initialize(request, configuration) @request = request @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/mobile_enhancements/request_helper.rb', line 15 def configuration @configuration end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
15 16 17 |
# File 'lib/mobile_enhancements/request_helper.rb', line 15 def request @request end |
Class Method Details
.delegated_methods ⇒ Object
7 8 9 10 11 |
# File 'lib/mobile_enhancements/request_helper.rb', line 7 def self.delegated_methods instance_methods.select do |name| name =~ /^(desktop|mobile)\_/ end + [:determine_layout, :determine_format] end |
Instance Method Details
#desktop_path(path = request.path) ⇒ Object
strips any mobile prefix from the path
43 44 45 46 47 |
# File 'lib/mobile_enhancements/request_helper.rb', line 43 def desktop_path(path = request.path) path.gsub(/^(.*?\/\/.*?)?\/(#{mobile_path_prefix}\/?)?(.*)$/) do "#{$1}/#{$3}" end.freeze end |
#desktop_request? ⇒ Boolean
returns whether or not this is a desktop request
67 68 69 |
# File 'lib/mobile_enhancements/request_helper.rb', line 67 def desktop_request? !mobile_request? end |
#desktop_url(url = request.url) ⇒ Object
strips any mobile prefix from the url
38 39 40 |
# File 'lib/mobile_enhancements/request_helper.rb', line 38 def desktop_url(url = request.url) desktop_path(url) end |
#determine_format ⇒ Object
returns what format should be used by the request
28 29 30 |
# File 'lib/mobile_enhancements/request_helper.rb', line 28 def determine_format mobile_request? ? mobile_format.to_sym : request.format.to_sym end |
#determine_layout ⇒ Object
returns a string defining which layout file to use
23 24 25 |
# File 'lib/mobile_enhancements/request_helper.rb', line 23 def determine_layout mobile_request? ? mobile_layout : desktop_layout end |
#mobile_param_value ⇒ Object
returns what the value of the mobile parameter should be
33 34 35 |
# File 'lib/mobile_enhancements/request_helper.rb', line 33 def mobile_param_value mobile_request? ? mobile_path_prefix : nil end |
#mobile_path(path = request.path) ⇒ Object
ensures a mobile prefix exists in the path
55 56 57 58 59 |
# File 'lib/mobile_enhancements/request_helper.rb', line 55 def mobile_path(path = request.path) path.gsub(/^(.*?\/\/.*?)?\/(#{mobile_path_prefix}\/?)?(.*)$/) do "#{$1}/#{mobile_path_prefix}/#{$3}" end.freeze end |
#mobile_request? ⇒ Boolean
returns whether or not this is a mobile request
62 63 64 |
# File 'lib/mobile_enhancements/request_helper.rb', line 62 def mobile_request? @mobile_request ||= !!(request.path =~ /^\/#{mobile_path_prefix}(\/.*)?$/) end |
#mobile_url(url = request.url) ⇒ Object
ensures a mobile prefix exists in the url
50 51 52 |
# File 'lib/mobile_enhancements/request_helper.rb', line 50 def mobile_url(url = request.url) mobile_path(url) end |