Sha256: 0f64f7d975728bf249ff81a1c04162c058fc9e99080ef01a6694462d89675ff3

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module WashOut
  # This class is a Rack middleware used to route SOAP requests to a proper
  # action of a given SOAP controller.
  class Router
    def initialize(controller_name)
      @controller_name = "#{controller_name.to_s}_controller".camelize
    end

    def call(env)
      controller = @controller_name.constantize

      if soap_action = env['HTTP_SOAPACTION']
        # RUBY18 1.8 does not have force_encoding.
        soap_action.force_encoding('UTF-8') if soap_action.respond_to? :force_encoding

        if WashOut::Engine.namespace
          namespace = Regexp.escape WashOut::Engine.namespace.to_s
          soap_action.gsub!(/^\"(#{namespace}(\/|#)?)?(.*)\"$/, '\3')
        else
          soap_action = soap_action[1...-1]
        end

        env['wash_out.soap_action'] = soap_action
      end

      action_spec = controller.soap_actions[soap_action]
      if action_spec
        action = action_spec[:to]
      else
        action = '_invalid_action'
      end

      controller.action(action).call(env)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wash_out-0.8.4 lib/wash_out/router.rb
wash_out-0.8.3 lib/wash_out/router.rb
wash_out-0.8.2 lib/wash_out/router.rb
wash_out-0.8.1 lib/wash_out/router.rb