Class: Mack::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Mack::Request
- Defined in:
- lib/mack/controller/request.rb,
lib/mack/controller/request/parameters.rb,
lib/mack/controller/request/date_time_parameter.rb
Defined Under Namespace
Classes: DateTimeParameter, Parameters, UploadedFile
Constant Summary
Constants inherited from Rack::Request
Rack::Request::FORM_DATA_MEDIA_TYPES
Instance Attribute Summary collapse
-
#session ⇒ Object
Gives access to the session.
Attributes inherited from Rack::Request
Instance Method Summary collapse
-
#file(key) ⇒ Object
Returns a Mack::Request::UploadedFile object.
-
#full_host ⇒ Object
Examples: example.org example.org example.org:8080.
-
#full_host_with_port ⇒ Object
Examples: example.org:80 example.org:443 example.org:8080.
-
#initialize(env) ⇒ Request
constructor
:nodoc:.
-
#merge_params(opts = {}) ⇒ Object
Merges another Hash with the parameters for this request.
-
#params ⇒ Object
Gives access to the request parameters.
-
#params=(p) ⇒ Object
:nodoc:.
-
#subdomains(tld_length = 1) ⇒ Object
Returns all the subdomains as an array, so [“dev”, “www”] would be returned for “dev.www.mackframework.com”.
Methods inherited from Rack::Request
#GET, #POST, #[], #[]=, #accept_encoding, #body, #content_charset, #content_length, #content_type, #cookies, #delete?, #form_data?, #fullpath, #get?, #head?, #host, #media_type, #media_type_params, #path_info, #path_info=, #port, #post?, #put?, #query_string, #referer, #request_method, #scheme, #script_name, #script_name=, #url, #values_at, #xhr?
Constructor Details
#initialize(env) ⇒ Request
:nodoc:
8 9 10 11 12 |
# File 'lib/mack/controller/request.rb', line 8 def initialize(env) # :nodoc: super(env) @mack_params = Mack::Request::Parameters.new parse_params(rack_params) end |
Instance Attribute Details
#session ⇒ Object
Gives access to the session. See Mack::Session for more information.
22 23 24 |
# File 'lib/mack/controller/request.rb', line 22 def session @session end |
Instance Method Details
#file(key) ⇒ Object
Returns a Mack::Request::UploadedFile object.
80 81 82 83 84 |
# File 'lib/mack/controller/request.rb', line 80 def file(key) ivar_cache("file_#{key}") do Mack::Request::UploadedFile.new(params[key] ||= {}) end end |
#full_host ⇒ Object
Examples:
http://example.org
https://example.org
http://example.org:8080
28 29 30 31 32 33 34 35 36 |
# File 'lib/mack/controller/request.rb', line 28 def full_host u = self.scheme.dup u << "://" u << self.host.dup unless self.port == 80 || self.port == 443 u << ":#{self.port}" end u end |
#full_host_with_port ⇒ Object
Examples:
http://example.org:80
https://example.org:443
http://example.org:8080
53 54 55 56 57 58 |
# File 'lib/mack/controller/request.rb', line 53 def full_host_with_port unless full_host.match(/:#{self.port}/) return full_host + ":#{self.port}" end return full_host end |
#merge_params(opts = {}) ⇒ Object
Merges another Hash with the parameters for this request.
17 18 19 |
# File 'lib/mack/controller/request.rb', line 17 def merge_params(opts = {}) parse_params(opts) end |
#params ⇒ Object
Gives access to the request parameters. This includes ‘get’ parameters, ‘post’ parameters as well as parameters from the routing process. The parameter will also be ‘unescaped’ when it is returned.
Example:
uri: '/users/1?foo=bar'
route: '/users/:id' => {:controller => 'users', :action => 'show'}
parameters: {:controller => 'users', :action => 'show', :id => 1, :foo => "bar"}
68 69 70 |
# File 'lib/mack/controller/request.rb', line 68 def params @mack_params end |
#params=(p) ⇒ Object
:nodoc:
72 73 74 75 |
# File 'lib/mack/controller/request.rb', line 72 def params=(p) # :nodoc: @mack_params = Mack::Request::Parameters.new parse_params(p) end |
#subdomains(tld_length = 1) ⇒ Object
Returns all the subdomains as an array, so [“dev”, “www”] would be returned for “dev.www.mackframework.com”. You can specify a different tld_length, such as 2 to catch [“www”] instead of [“www”, “mackframework”] in “www.mackframework.co.uk”.
Thanks Ruby on Rails for this.
43 44 45 46 47 |
# File 'lib/mack/controller/request.rb', line 43 def subdomains(tld_length = 1) return [] unless named_host?(host) parts = host.split('.') parts[0..-(tld_length+2)] end |