Sha256: 7d3f51211d11457c741a1b111ab311aeb31988bfec23e47a1f1be022178bb4ea

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

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(router, location = nil, &block)
      @handler_class = Class.new do
        include Deas::ViewHandler

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

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

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

        attr_reader :redirect_location

        def init!
          @redirect_location = self.class.router.prepend_base_url(
            self.instance_eval(&self.class.redirect_location)
          )
        end

        def run!
          redirect @redirect_location
        end

      end

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

    def validate!; end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
deas-0.43.5 lib/deas/redirect_proxy.rb
deas-0.43.4 lib/deas/redirect_proxy.rb
deas-0.43.3 lib/deas/redirect_proxy.rb
deas-0.43.2 lib/deas/redirect_proxy.rb
deas-0.43.1 lib/deas/redirect_proxy.rb
deas-0.43.0 lib/deas/redirect_proxy.rb
deas-0.42.0 lib/deas/redirect_proxy.rb
deas-0.41.0 lib/deas/redirect_proxy.rb
deas-0.40.0 lib/deas/redirect_proxy.rb
deas-0.39.2 lib/deas/redirect_proxy.rb
deas-0.39.1 lib/deas/redirect_proxy.rb
deas-0.39.0 lib/deas/redirect_proxy.rb