Skip to content

Commit

Permalink
use router to provide same functionality for Rails API
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Sep 29, 2016
1 parent 1d856ce commit 2abc76c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def all
end
end

def proxy
params[:name] = request.env['washout_builder.controller_path']
all
end

private

# tries to find all services by searching through the rails controller
Expand Down Expand Up @@ -58,7 +63,7 @@ def all_services
'documentation_url' => service_documentation_url(hash, controller_name)
}
end
end
end.uniq{|hash| hash['service_name'] }
end

def generate_wsdl_action
Expand Down
5 changes: 1 addition & 4 deletions lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

Gem.find_files('washout_builder/**/*.rb').each { |path| require path }


ActionDispatch::Routing::Mapper.class_eval do
alias_method :original_wash_out, :wash_out
# Adds the routes for a SOAP endpoint at +controller+.
Expand All @@ -25,9 +24,7 @@ def wash_out(controller_name, options={})
else
controller_class_name = controller_name.to_s.underscore
end

match "#{controller_name}/soap_doc" => WashoutBuilder::Engine, via: :get,
defaults: { name: "#{controller_class_name}" },
match "#{controller_name}/soap_doc" => WashoutBuilder::Router.new(controller_class_name), via: :get,
format: false,
as: "#{controller_class_name}_soap_doc"
end
Expand Down
16 changes: 16 additions & 0 deletions lib/washout_builder/router.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module WashoutBuilder
# 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_path)
@controller_path = controller_path
end

def call(env)
env['washout_builder.controller_path'] = @controller_path
WashoutBuilderController.action(:proxy).call(env)
end

end
end
4 changes: 2 additions & 2 deletions lib/washout_builder/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module VERSION
# the major version of the gem
MAJOR = 1
# the minor version of the gem
MINOR = 5
MINOR = 6
# the tiny version of the gem
TINY = 6
TINY = 0
# if the version should be a prerelease
PRE = nil

Expand Down

0 comments on commit 2abc76c

Please sign in to comment.