Sha256: 8948b99585d9847e071af552e097f377732cd41daee02f7b39abac40f0eedf6b

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

require 'deas/handler_proxy'
require 'deas/url'
require 'deas/view_handler'

module Deas

  class RedirectProxy < HandlerProxy

    attr_reader :handler_class_name, :handler_class

    def initialize(path = nil, &block)
      @handler_class = Class.new do
        include Deas::ViewHandler

        def self.redirect_path; @redirect_path; end
        def self.redirect_path=(value)
          @redirect_path = value
        end

        def self.name; 'Deas::RedirectHandler'; end

        attr_reader :redirect_path

        def init!
          @redirect_path = self.instance_eval(&self.class.redirect_path)
        end

        def run!
          redirect @redirect_path
        end

      end

      @handler_class.redirect_path = if path.nil?
        block
      elsif path.kind_of?(Deas::Url)
        proc{ path.path_for(params) }
      else
        proc{ path }
      end
      @handler_class_name = @handler_class.name
    end

    def validate!; end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deas-0.35.0 lib/deas/redirect_proxy.rb
deas-0.34.0 lib/deas/redirect_proxy.rb
deas-0.33.0 lib/deas/redirect_proxy.rb
deas-0.32.0 lib/deas/redirect_proxy.rb