Sha256: 959b1d1c5ac3ce8f3cb380b46e3c1e2cccd917f47d76f3bc0f811929ebeda06e

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'jeanine/callbacks'
require 'jeanine/mimes'
require 'jeanine/request'
require 'jeanine/response'
require 'jeanine/renderer'
require 'jeanine/routing'

module Jeanine
  class App
    include Routing::Evaluation
    attr_reader :request, :response
    class << self
      include Routing::DSL
      include Callbacks

      alias :_new :new
      def new(*args, &block)
        initialize!
        stack.run _new(*args, &block)
        stack
      end

      def initialize!
        Mimes.load!
      end

      def stack
        @stack ||= Rack::Builder.new
      end

      def router
        Jeanine.router
      end

      def call(env)
        new.call env
      end
    end

    def call(env)
      @env = env
      @request = Jeanine::Request.new(env)
      @response = Jeanine::Response.new
      catch(:halt) { route_eval }
    end

    private

    def params
      @params ||= if @request.format
                    @request.params.merge({ format: @request.format })
                  else
                    @request.params
                  end
    end

    def render(*args)
      @response.action_variables = instance_variables_cache
      Renderer.new(@response).render(*args)
    end

    def instance_variables_cache
      instance_variables.each_with_object({}) do |var, obj|
        obj[var] = instance_variable_get(var)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jeanine-0.1.0 lib/jeanine/app.rb