Sha256: 54e0c3118daeeae2e84c092574223402e28899c90f12c1e365e3a094384ef096

Contents?: true

Size: 1.97 KB

Versions: 18

Compression:

Stored size: 1.97 KB

Contents

require 'rubygems'
require 'bundler/setup'

require 'facets/string/interpolate'
require 'rack'

module RubyApp
  require 'ruby_app/application'
  require 'ruby_app/language'
  require 'ruby_app/mixins/delegate_mixin'
  require 'ruby_app/mixins/render_mixin'
  require 'ruby_app/session'

  class Request < ::Rack::Request
    extend RubyApp::Mixins::DelegateMixin

    def language
      self.fullpath =~ /^\/([^\/\?]+)/
      $1 || RubyApp::Application.options.default_language
    end

    def query
      ::Rack::Utils.parse_query(self.query_string)
    end

    def parameters
      self.params
    end

    def rendered?(template)
      @rendered.key?(template)
    end

    def rendered(template)
      @rendered[template] = true
    end

    def content_for(element, name, value = nil, &block)
      @content[element] ||= {}
      @content[element][name] = block_given? ? block : String.interpolate { value }
    end

    def get_content(element, name)
      @content[element] ||= {}
      return @content[element][name]
    end

    def clear_content(element)
      @content[element] ||= {}
    end

    def self.get
      Thread.current[:_request]
    end

    def self.create!(environment = RubyApp::Application.environment)
      Thread.current[:_request] = RubyApp::Request.new(environment)

      if block_given?
        begin
          RubyApp::Language.load! do
            RubyApp::Session.create! do
              return yield
            end
          end
        ensure
          self.destroy!
        end
      else
        begin
          RubyApp::Language.load!
          begin
            RubyApp::Session.create!
          rescue
            RubyApp::Language.unload!
            raise
          end
        rescue
          self.destroy!
          raise
        end
      end

    end

    def self.destroy!
      Thread.current[:_request] = nil
    end

    private

      def initialize(environment)
        super(environment)
        @rendered = {}
        @content = {}
      end

  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
RubyApp-0.0.91 lib/ruby_app/request.rb
RubyApp-0.0.90 lib/ruby_app/request.rb
RubyApp-0.0.89 lib/ruby_app/request.rb
RubyApp-0.0.88 lib/ruby_app/request.rb
RubyApp-0.0.87 lib/ruby_app/request.rb
RubyApp-0.0.86 lib/ruby_app/request.rb
RubyApp-0.0.85 lib/ruby_app/request.rb
RubyApp-0.0.84 lib/ruby_app/request.rb
RubyApp-0.0.83 lib/ruby_app/request.rb
RubyApp-0.0.82 lib/ruby_app/request.rb
RubyApp-0.0.81 lib/ruby_app/request.rb
RubyApp-0.0.80 lib/ruby_app/request.rb
RubyApp-0.0.79 lib/ruby_app/request.rb
RubyApp-0.0.78 lib/ruby_app/request.rb
RubyApp-0.0.77 lib/ruby_app/request.rb
RubyApp-0.0.76 lib/ruby_app/request.rb
RubyApp-0.0.75 lib/ruby_app/request.rb
RubyApp-0.0.70 lib/ruby_app/request.rb