class Puuko::Application

Public Class Methods

configuration() click to toggle source
# File lib/puuko/application.rb, line 21
def configuration
  @configuration
end
configure(klass = nil) { |configuration| ... } click to toggle source
# File lib/puuko/application.rb, line 11
def configure(klass = nil)
  @configuration = klass.new if klass
  yield @configuration if block_given?
  @configuration
end
logger() click to toggle source
# File lib/puuko/application.rb, line 17
def logger
  @configuration.logger
end
new() click to toggle source
# File lib/puuko/application.rb, line 26
def initialize
  @routes = []
end

Public Instance Methods

configuration() click to toggle source
# File lib/puuko/application.rb, line 50
def configuration
  self.class.configuration
end
delete(path, to: Puuko::Endpoints::NotFound, params: {}) click to toggle source
# File lib/puuko/application.rb, line 46
def delete(path, to: Puuko::Endpoints::NotFound, params: {})
  @routes << Puuko::Route.new(:delete, path, to, params)
end
get(path, to: Puuko::Endpoints::NotFound, params: {}) click to toggle source
# File lib/puuko/application.rb, line 30
def get(path, to: Puuko::Endpoints::NotFound, params: {})
  @routes << Puuko::Route.new(:get, path, to, params)
end
logger() click to toggle source
# File lib/puuko/application.rb, line 54
def logger
  self.class.logger
end
patch(path, to: Puuko::Endpoints::NotFound, params: {}) click to toggle source
# File lib/puuko/application.rb, line 42
def patch(path, to: Puuko::Endpoints::NotFound, params: {})
  @routes << Puuko::Route.new(:patch, path, to, params)
end
post(path, to: Puuko::Endpoints::NotFound, params: {}) click to toggle source
# File lib/puuko/application.rb, line 34
def post(path, to: Puuko::Endpoints::NotFound, params: {})
  @routes << Puuko::Route.new(:post, path, to, params)
end
put(path, to: Puuko::Endpoints::NotFound, params: {}) click to toggle source
# File lib/puuko/application.rb, line 38
def put(path, to: Puuko::Endpoints::NotFound, params: {})
  @routes << Puuko::Route.new(:put, path, to, params)
end
rack_app() click to toggle source
# File lib/puuko/application.rb, line 62
def rack_app
  klass = Class.new(Puuko::Base) do
    set :protection, except: :json_csrf

    configure :production, :development do
      enable :logging
    end
  end

  configuration.before_filters.each do |before_filter|
    klass.before(&before_filter)
  end

  @routes.each do |route|
    logger.debug "Register #{route.verb} #{route.path} to #{route.endpoint.name}"

    klass.public_send(route.verb, route.path) do
      handler = route.endpoint.new(request, route.params.merge(params))
      handler.execute

      [
        handler.response.status,
        handler.response.headers,
        handler.response.body.to_json
      ]
    end
  end

  configuration.after_filters.each do |after_filter|
    klass.after(&after_filter)
  end

  klass
end
router=(router) click to toggle source
# File lib/puuko/application.rb, line 58
def router=(router)
  router.apply(self)
end