Sha256: f223b28483058876ca6a14f181c74eefbb15324f1e3a0f4bafd6389ad4615101

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

require 'orange-core/middleware/base'
module Orange::Middleware
  
  class Rerouter < Base
    def init(*args)
      orange.add_pulp Orange::Pulp::Packet_Reroute
    end
    
    def packet_call(packet)
      begin
        pass packet
      rescue Orange::Reroute
        packet.finish
      end
    end
  end
end

module Orange
  
  module Pulp::Packet_Reroute
    def reroute(url, type = :real, *args)
      packet['reroute.to'] = url
      packet['reroute.type'] = type
      packet['reroute.args'] = *args if args
      raise Reroute.new(self), 'Unhandled reroute'
    end
  end
  
  class Reroute < Exception
    def initialize(packet)
      @packet = packet
      @packet[:headers] = {"Content-Type" => 'text/html', "Location" => self.url}
      @packet[:status] = 302
    end
    
    def url
      case packet['reroute.type']
      when :real
        packet['reroute.to']
      # Parsing for orange urls or something
      when :orange
        packet.route_to(packet['reroute.to'], *packet['reroute.args', []])
      else
        packet['reroute.to']
      end
    end
    
    def packet
      @packet
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
orange-core-0.7.0 lib/orange-core/middleware/rerouter.rb
orange-core-0.6.0 lib/orange-core/middleware/rerouter.rb
orange-core-0.5.9 lib/orange-core/middleware/rerouter.rb
orange-core-0.5.8 lib/orange-core/middleware/rerouter.rb
orange-core-0.5.5 lib/orange-core/middleware/rerouter.rb
orange-core-0.5.3 lib/orange-core/middleware/rerouter.rb
orange-0.5.5 lib/orange-core/middleware/rerouter.rb
orange-0.5.4 lib/orange-core/middleware/rerouter.rb
orange-0.5.3 lib/orange-core/middleware/rerouter.rb
orange-0.5.2 lib/orange-core/middleware/rerouter.rb
orange-0.5.1 lib/orange-core/middleware/rerouter.rb
orange-0.4.0 lib/orange-core/middleware/rerouter.rb
orange-0.3.9 lib/orange-core/middleware/rerouter.rb
orange-0.3.8 lib/orange-core/middleware/rerouter.rb
orange-0.3.7 lib/orange-core/middleware/rerouter.rb
orange-0.3.6 lib/orange-core/middleware/rerouter.rb
orange-0.3.5 lib/orange-core/middleware/rerouter.rb
orange-0.3.4 lib/orange-core/middleware/rerouter.rb
orange-0.3.3 lib/orange-core/middleware/rerouter.rb
orange-0.3.2 lib/orange-core/middleware/rerouter.rb