Class: Mack::Request
- Defined in:
- lib/mack/controller/request.rb
Defined Under Namespace
Classes: DateTimeParameter, Parameters, UploadedFile
Instance Attribute Summary collapse
-
#session ⇒ Object
Gives access to the session.
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”.
Constructor Details
#initialize(env) ⇒ Request
:nodoc:
30 31 32 33 34 |
# File 'lib/mack/controller/request.rb', line 30 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.
44 45 46 |
# File 'lib/mack/controller/request.rb', line 44 def session @session end |
Instance Method Details
#file(key) ⇒ Object
Returns a Mack::Request::UploadedFile object.
102 103 104 105 106 |
# File 'lib/mack/controller/request.rb', line 102 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
50 51 52 53 54 55 56 57 58 |
# File 'lib/mack/controller/request.rb', line 50 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
75 76 77 78 79 80 |
# File 'lib/mack/controller/request.rb', line 75 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.
39 40 41 |
# File 'lib/mack/controller/request.rb', line 39 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"}
90 91 92 |
# File 'lib/mack/controller/request.rb', line 90 def params @mack_params end |
#params=(p) ⇒ Object
:nodoc:
94 95 96 97 |
# File 'lib/mack/controller/request.rb', line 94 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.
65 66 67 68 69 |
# File 'lib/mack/controller/request.rb', line 65 def subdomains(tld_length = 1) return [] unless named_host?(host) parts = host.split('.') parts[0..-(tld_length+2)] end |