Sha256: 9a42d0f3851b9c531d14d22f9f134dbe4dc5da30c483e704595b4c9b0f52a0c3

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require 'rubygems'
require 'bundler/setup'

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

module RubyApp
  require 'ruby_app/mixins'

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

    def rendered?(template)
      return @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
      return Thread.current[:_response]
    end

    def self.create!
      Thread.current[:_response] = RubyApp::Response.new
    end

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

    private

      def initialize
        super
        self['Cache-Control'] = 'no-cache'
        @rendered = {}
        @content = {}
      end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
RubyApp-0.2.4 lib/ruby_app/response.rb
RubyApp-0.2.3 lib/ruby_app/response.rb
RubyApp-0.2.2 lib/ruby_app/response.rb
RubyApp-0.2.1 lib/ruby_app/response.rb
RubyApp-0.2.0 lib/ruby_app/response.rb