Sha256: f34c1bd48b107d405b9a1926054064cd3f8be5cf48ea07008bdb373e91d72136

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 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
      @app_settings  = @sinatra_call.settings
      @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

2 entries across 2 versions & 1 rubygems

Version Path
deas-0.9.0 lib/deas/sinatra_runner.rb
deas-0.8.0 lib/deas/sinatra_runner.rb