Parent

Class Index [+]

Quicksearch

Ramaze::Request

The purpose of this class is to act as a simple wrapper for Rack::Request and provide some convinient methods for our own use.

Constants

INTERESTING_HTTP_VARIABLES
REQUEST_STRING_FORMAT

Public Instance Methods

accept_charset(default = 'UTF-8') click to toggle source
    # File lib/ramaze/request.rb, line 39
39:     def accept_charset(default = 'UTF-8')
40:       return default unless charsets = env['HTTP_ACCEPT_CHARSET']
41:       charset = charsets.split(',', 2).first
42:       charset == '*' ? default : charset
43:     end
accept_language(string = env['HTTP_ACCEPT_LANGUAGE']) click to toggle source

Try to find out which languages the client would like to have and sort them by weight, (most wanted first).

Returns and array of locales from env[‘HTTP_ACCEPT_LANGUAGE]. e.g. [“fi”, “en”, “ja”, “fr”, “de”, “es”, “it”, “nl”, “sv”]

Usage:

    request.accept_language # => ['en-us', 'en', 'de-at', 'de']

@param [String #] string the value of HTTP_ACCEPT_LANGUAGE @return [Array] list of locales @see Request#accept_language_with_weight @author manveru

    # File lib/ramaze/request.rb, line 61
61:     def accept_language(string = env['HTTP_ACCEPT_LANGUAGE'])
62:       return [] unless string
63: 
64:       accept_language_with_weight(string).map{|lang, weight| lang }
65:     end
Also aliased as: locales
accept_language_with_weight(string = env['HTTP_ACCEPT_LANGUAGE']) click to toggle source

Transform the HTTP_ACCEPT_LANGUAGE header into an Array with:

    [[lang, weight], [lang, weight], ...]

This algorithm was taken and improved from the locales library.

Usage:

    request.accept_language_with_weight
    # => [["en-us", 1.0], ["en", 0.8], ["de-at", 0.5], ["de", 0.3]]

@param [String #] string the value of HTTP_ACCEPT_LANGUAGE @return [Array] array of [lang, weight] arrays @see Request#accept_language @author manveru

    # File lib/ramaze/request.rb, line 85
85:     def accept_language_with_weight(string = env['HTTP_ACCEPT_LANGUAGE'])
86:       string.to_s.gsub(/\s+/, '').split(',').
87:             map{|chunk|        chunk.split(';q=', 2) }.
88:             map{|lang, weight| [lang, weight ? weight.to_f : 1.0] }.
89:         sort_by{|lang, weight| -weight }
90:     end
http_variables() click to toggle source

Interesting HTTP variables from env

    # File lib/ramaze/request.rb, line 96
96:     def http_variables
97:       env.reject{|key, value| key.to_s !~ INTERESTING_HTTP_VARIABLES }
98:     end
Also aliased as: http_vars
http_vars() click to toggle source
Alias for: http_variables
inspect() click to toggle source
Alias for: to_s
locales(string = env['HTTP_ACCEPT_LANGUAGE']) click to toggle source
Alias for: accept_language
method_missing(meth, *args) click to toggle source

you can access the original @request via this method_missing, first it tries to match your method with any of the HTTP parameters then, in case that fails, it will relay to @request

    # File lib/ramaze/request.rb, line 12
12:     def method_missing meth, *args
13:       key = meth.to_s.upcase
14:       return env[key] if env.has_key?(key)
15:       super
16:     end
pretty_print(pp) click to toggle source

Pretty prints current action with parameters, cookies and enviroment variables.

     # File lib/ramaze/request.rb, line 110
110:     def pretty_print(pp)
111:       pp.object_group(self) do
112:         group = {
113:           'params'  => params,
114:           'cookies' => cookies,
115:           'env'     => http_variables
116:         }
117: 
118:         group.each do |name, hash|
119:           pp.breakable
120:           pp.text " @#{name}="
121:           pp.nest(name.size + 3){ pp.pp_hash(hash) }
122:         end
123:       end
124:     end
to_instance_variables(*args) click to toggle source

Sets any arguments passed as @instance_variables for the current action.

Usage:

    request.params # => {'name' => 'manveru', 'q' => 'google', 'lang' => 'de'}
    request.to_ivs(:name, :q)

    @q    # => 'google'
    @name # => 'manveru'
    @lang # => nil
    # File lib/ramaze/request.rb, line 30
30:     def to_instance_variables(*args)
31:       instance = Current.action.instance
32:       args.each do |arg|
33:         next unless value = self[arg]
34:         instance.instance_variable_set("@#{arg}", value)
35:       end
36:     end
Also aliased as: to_ivs
to_ivs(*args) click to toggle source
to_s() click to toggle source
     # File lib/ramaze/request.rb, line 103
103:     def to_s
104:       REQUEST_STRING_FORMAT % [self.class, params, cookies, http_variables]
105:     end
Also aliased as: inspect

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.