Class: Ramaze::Request

### Home Classes Methods

### In Files

- lib/ramaze/request.rb

### Parent

Innate::Request

### Methods

- #accept_charset
- #accept_language
- #accept_language_with_weight
- #http_variables
- #http_vars
- #inspect
- #locales
- #method_missing
- #pretty_print
- #to_instance_variables
- #to_ivs
- #to_s

### Files

- Gemfile
- Rakefile

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::Bin
- Ramaze::Bin::Create
- Ramaze::Bin::Runner
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Files
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Informer
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logging
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Innate
- Innate::View
- Innate::View::Slim
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- MainController
- Object

No matching classes.

# 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
    def accept_charset(default = 'UTF-8')
      return default unless charsets = env['HTTP_ACCEPT_CHARSET']
      charset = charsets.split(',', 2).first
      charset == '*' ? default : charset
    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. e.g. ["fi", "en", "ja", "fr", "de", "es", "it", "nl", "sv"]

Usage:

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

@param [String to_s] 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
    def accept_language(string = env['HTTP_ACCEPT_LANGUAGE'])
      return [] unless string

      accept_language_with_weight(string).map{|lang, weight| lang }
    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 to_s] 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
    def accept_language_with_weight(string = env['HTTP_ACCEPT_LANGUAGE'])
      string.to_s.gsub(/\s+/, '').split(',').
            map{|chunk|        chunk.split(';q=', 2) }.
            map{|lang, weight| [lang, weight ? weight.to_f : 1.0] }.
        sort_by{|lang, weight| -weight }
    end

http_variables() click to toggle source

Interesting HTTP variables from env

    # File lib/ramaze/request.rb, line 96
    def http_variables
      env.reject{|key, value| key.to_s !~ INTERESTING_HTTP_VARIABLES }
    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
    def method_missing meth, *args
      key = meth.to_s.upcase
      return env[key] if env.has_key?(key)
      super
    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
    def pretty_print(pp)
      pp.object_group(self) do
        group = {
          'params'  => params,
          'cookies' => cookies,
          'env'     => http_variables
        }

        group.each do |name, hash|
          pp.breakable
          pp.text " @#{name}="
          pp.nest(name.size + 3){ pp.pp_hash(hash) }
        end
      end
    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
    def to_instance_variables(*args)
      instance = Current.action.instance
      args.each do |arg|
        next unless value = self[arg]
        instance.instance_variable_set("@#{arg}", value)
      end
    end

Also aliased as: to_ivs
to_ivs(*args) click to toggle source
Alias for: to_instance_variables
to_s() click to toggle source

    # File lib/ramaze/request.rb, line 103
    def to_s
      REQUEST_STRING_FORMAT % [self.class, params, cookies, http_variables]
    end

Also aliased as: inspect

[Validate]

Generated with the Darkfish Rdoc Generator 2.