Sha256: 1ecbc5d9851abcfb6d7ef49af59be6a84755c3a33a3a9916de0ddf8c6d31e5d9

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

require 'deas/runner'
require 'deas/template'

module Deas

  class SinatraRunner < Runner

    def self.run(*args)
      self.new(*args).run
    end

    def initialize(handler_class, sinatra_call)
      @sinatra_call  = sinatra_call
      @handler_class = handler_class
      @logger        = @sinatra_call.settings.logger
      @params        = @sinatra_call.params
      @request       = @sinatra_call.request
      @response      = @sinatra_call.response
      @session       = @sinatra_call.session
      super(handler_class)
    end

    def run
      run_callbacks @handler_class.before_callbacks
      @handler.init
      response_data = @handler.run
      run_callbacks @handler_class.after_callbacks
      response_data
    end

    # Helpers

    def halt(*args)
      @sinatra_call.halt(*args)
    end

    def render(name, options = nil, &block)
      options ||= {}
      options[:locals] = { :view => @handler }.merge(options[:locals] || {})
      options[:layout] ||= @handler_class.layouts
      Deas::Template.new(@sinatra_call, name, options).render(&block)
    end

    def redirect(*args)
      @sinatra_call.redirect(*args)
    end

    def redirect_to(path, *args)
      @sinatra_call.redirect(@sinatra_call.to(path), *args)
    end

    private

    def run_callbacks(callbacks)
      callbacks.each{|proc| @handler.instance_eval(&proc) }
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
deas-0.7.0 lib/deas/sinatra_runner.rb
deas-0.6.0 lib/deas/sinatra_runner.rb
deas-0.5.0 lib/deas/sinatra_runner.rb
deas-0.4.1 lib/deas/sinatra_runner.rb
deas-0.4.0 lib/deas/sinatra_runner.rb
deas-0.3.0 lib/deas/sinatra_runner.rb