Sha256: 9550f7f3f340df60461154b0145b84df20d3bb99b637ae858d5a76b5e492a1de

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module Pakyow

  # The Request object.
  class Request < Rack::Request
    attr_accessor :restful, :route_spec, :controller, :action, :format, :error

    # Easy access to path_info.
    def path
      self.path_info
    end
    
    # Determines the request method.
    def method
      request_method.downcase.to_sym
    end

    def format=(format)
      @format = format ? format.to_sym : :html
      
      # Set response type
      Pakyow.app.response["Content-Type"] = Rack::Mime.mime_type(".#{@format}")
    end
    
    def session
      env['rack.session'] || {}
    end
    
    def cookies
      @cookies ||= HashUtils.strhash(super)
    end
    
    # Returns indifferent params (see {HashUtils.strhash} for more info on indifferent hashes).
    def params
      @params ||= HashUtils.strhash(super)
    end
    
    # Returns array of url components.
    def url_parts
      unless @url
        @url = self.class.split_url(self.env['PATH_INFO'])
      end
    
      return @url
    end
    
    # Returns array of referer components.
    def referer_parts
      unless @referer
        @referer = self.class.split_url(self.env['HTTP_REFERER'])
      end
    
      return @referer
    end
    
    private
    
    def self.split_url(url)
      arr = []
      url.split('/').each { |r|
        arr << r unless r.empty?
      }
      
      return arr
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-core-0.6.3.1 pakyow-core/lib/core/request.rb
pakyow-core-0.6.1 pakyow-core/lib/core/request.rb