Sha256: fc0272540752f73761ac2c6cadbc83e38ccc2aa80292b0f4006c304a37586326

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

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

module Jeanine
  class App
    include Routing::Evaluation

    attr_reader :request, :response

    def self.plugin(name)
      unless Jeanine._installed_plugins.include?(name)
        unless const_defined?("Jeanine::#{name}")
          require "jeanine/#{name.to_s.underscore}"
        end
        include Kernel.const_get("Jeanine::#{name}")
        Jeanine._installed_plugins << name
      end
    end

    def self.installed_plugins
      Jeanine._installed_plugins
    end

    # plugin :Callbacks
    # plugin :Rendering
    # plugin :Rescuing
    # plugin :Session

    class << self
      include Routing::DSL

      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 instance_variables_cache
      instance_variables.each_with_object({}) do |var, obj|
        obj[var] = instance_variable_get(var)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jeanine-0.8.1 lib/jeanine/app.rb
jeanine-0.8 lib/jeanine/app.rb
jeanine-0.7.8 lib/jeanine/app.rb
jeanine-0.7.7 lib/jeanine/app.rb
jeanine-0.7.6 lib/jeanine/app.rb
jeanine-0.7.2 lib/jeanine/app.rb
jeanine-0.7.1 lib/jeanine/app.rb
jeanine-0.7.0 lib/jeanine/app.rb
jeanine-0.6.0 lib/jeanine/app.rb
jeanine-0.5.0 lib/jeanine/app.rb