Sha256: ec2f47d77b6835e3e3656b848e587aa3b0700496d762bae5a04f87dd8d726ee2

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

require 'happy/request'
require 'happy/context_ext/helpers'

module Happy
  class Context
    include ContextExtensions::Helpers

    attr_reader   :request, :response, :remaining_path
    attr_accessor :layout, :controller
    delegate      :params, :session, :to => :request

    def initialize(request, response)
      @request    = request
      @response   = response
      @remaining_path = @request.path.split('/').reject {|s| s.blank? }
      @layout     = nil
      @controller = nil
    end

    def with_controller(new_controller)
      # remember previous controller
      old_controller = self.controller
      self.controller = new_controller

      # execute permissions block    SMELL - better integration
      if controller.class.respond_to?(:permissions_blk)
        controller.class.permissions_blk.try(:call, permissions, self)
      end

      # execute block
      yield
    ensure
      # switch back to previous controller
      self.controller = old_controller
    end

    def response=(r)
      @response = r
    end

  private

    class << self
      def from_env(env)
        new(Happy::Request.new(env), Rack::Response.new)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
happy-0.1.0.pre8 lib/happy/context.rb
happy-0.1.0.pre7 lib/happy/context.rb
happy-0.1.0.pre.6 lib/happy/context.rb
happy-0.1.0.pre.5 lib/happy/context.rb
happy-0.1.0.pre.4 lib/happy/context.rb
happy-0.1.0.pre.3 lib/happy/context.rb