From 38a2339620db57a0d761b7ad3d1e7bad696a65f1 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Fri, 23 May 2014 13:10:30 +0300 Subject: [PATCH 1/2] remove dispatcher --- .../washout_builder_controller.rb | 6 +-- config/routes.rb | 2 +- lib/washout_builder.rb | 17 ------ lib/washout_builder/dispatcher.rb | 28 ---------- lib/washout_builder/soap.rb | 1 - lib/washout_builder/version.rb | 2 +- spec/lib/washout_builder/dispatcher_spec.rb | 54 ------------------- 7 files changed, 5 insertions(+), 105 deletions(-) delete mode 100644 lib/washout_builder/dispatcher.rb delete mode 100644 spec/lib/washout_builder/dispatcher_spec.rb diff --git a/app/controllers/washout_builder/washout_builder_controller.rb b/app/controllers/washout_builder/washout_builder_controller.rb index 0b3d78d..22cd4e1 100644 --- a/app/controllers/washout_builder/washout_builder_controller.rb +++ b/app/controllers/washout_builder/washout_builder_controller.rb @@ -48,13 +48,13 @@ def all_controllers def map_controllers all_controllers.map do |route| - route.defaults[:controller] if route.defaults[:action] == "_generate_doc" + route.defaults[:controller] if route.defaults[:action] == "_generate_wsdl" end.uniq.compact end def controller_is_a_service?(controller) route = all_controllers.detect do |route| - route.defaults[:controller].try(:camelize) == controller.camelize && route.defaults[:action] == "_generate_doc" + route.defaults[:controller].try(:camelize) == controller.camelize && route.defaults[:action] == "_generate_wsdl" end end @@ -71,7 +71,7 @@ def service_endpoint(controller_name) end def service_documentation_url(controller_name) - "#{request.protocol}#{request.host_with_port}/#{controller_name}/doc" + "#{washout_builder.root_url}#{controller_name.camelize}" end end diff --git a/config/routes.rb b/config/routes.rb index e693f21..96771b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ WashoutBuilder::Engine.routes.draw do root :to =>"washout_builder#all" - match '*name' => "washout_builder#all", :as => :washout_builder_service, :via => :get + match '/*name' => "washout_builder#all", :as => :washout_builder_service, :via => :get end \ No newline at end of file diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index 325b2c8..ef6fd07 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -6,27 +6,10 @@ require 'washout_builder/document/complex_type' require 'washout_builder/document/virtus_model' require 'washout_builder/document/generator' -require 'washout_builder/dispatcher' require 'washout_builder/type' require 'washout_builder/version' -module ActionDispatch::Routing - class Mapper - - alias_method :original_wash_out,:wash_out - - # Adds the routes for a SOAP endpoint at +controller+. - def wash_out(controller_name, options={}) - options.reverse_merge!(@scope) if @scope - - match "#{controller_name}/doc" => "#{controller_name}#_generate_doc", :via => :get, :format => false - original_wash_out(controller_name, options) - - - end - end -end Virtus::InstanceMethods::Constructor.class_eval do alias_method :original_initialize,:initialize diff --git a/lib/washout_builder/dispatcher.rb b/lib/washout_builder/dispatcher.rb deleted file mode 100644 index 57269d7..0000000 --- a/lib/washout_builder/dispatcher.rb +++ /dev/null @@ -1,28 +0,0 @@ - -module WashoutBuilder - # The WashoutBuilder::Dispatcher module should be included in a controller acting - # as a SOAP endpoint. It includes actions for generating WSDL and handling - # SOAP requests. - module Dispatcher - - def _generate_doc - @document = WashoutBuilder::Document::Generator.new( - :config => soap_config, - :service_class => self.class, - :soap_actions => self.class.soap_actions - ) - - render :template => "wash_with_html/doc", :layout => false, - :content_type => 'text/html' - end - - def self.included(controller) - controller.send :helper,:washout_builder - controller.send :before_filter, :_authenticate_wsse, :except => [ - :_generate_wsdl, :_generate_doc,:_invalid_action ] - controller.send :before_filter, :_map_soap_parameters, :except => [ - :_generate_wsdl,:_generate_doc, :_invalid_action ] - end - - end -end \ No newline at end of file diff --git a/lib/washout_builder/soap.rb b/lib/washout_builder/soap.rb index 1c3b8f6..1f34b5b 100644 --- a/lib/washout_builder/soap.rb +++ b/lib/washout_builder/soap.rb @@ -38,7 +38,6 @@ def soap_action(action, options={}) included do include WashOut::Configurable if defined?(WashOut::Configurable) include WashOut::Dispatcher if defined?(WashOut::Dispatcher) - include WashoutBuilder::Dispatcher self.soap_actions = {} end end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index f95873c..3ecd627 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.11.8" + VERSION = "0.12.0" end diff --git a/spec/lib/washout_builder/dispatcher_spec.rb b/spec/lib/washout_builder/dispatcher_spec.rb deleted file mode 100644 index e02f6ba..0000000 --- a/spec/lib/washout_builder/dispatcher_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -#encoding:utf-8 - -require 'spec_helper' -mock_controller do - soap_action 'dispatcher_method', :args => nil, :return => nil - - def dispatcher_method - #nothing - end -end - -describe ApiController, :type => :controller do - - let(:document) { WashoutBuilder::Document::Generator.new} - - render_views(false) - - before(:each) do - WashoutBuilder::Document::Generator.stubs(:new).returns(document) - end - - it "inits the document generator" do - WashoutBuilder::Document::Generator.expects(:new).with( - :config => ApiController.soap_config, - :service_class => ApiController, - :soap_actions => {"dispatcher_method"=>{ - :args=>nil, - :return=>nil, - :in=>[], - :out=>[], - :to=>"dispatcher_method", - :response_tag=>"tns:dispatcher_methodResponse", - :builder_in=>[], - :builder_out=>[] - } - } - ) - get :_generate_doc - end - - it "verifies render" do - controller.expects(:render).with(nil) - controller.expects(:render).with(:template => "wash_with_html/doc", :layout => false, - :content_type => 'text/html') - get :_generate_doc - end - - it "renders the template" , :fails =>true do - get :_generate_doc - response.should render_template("wash_with_html/doc") - end - - -end \ No newline at end of file From ea478d160f64efb70ae70a43a218f407fce0359d Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Fri, 23 May 2014 13:14:46 +0300 Subject: [PATCH 2/2] readme --- README.rdoc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 396dba5..185d442 100644 --- a/README.rdoc +++ b/README.rdoc @@ -72,13 +72,18 @@ In the following file +config/routes.rb+ you can put this configuration wash_out :rumbas wash_out :my_other_service + namespace :api do + wash_out :project_service + end + mount WashoutBuilder::Engine => "/washout" end You can access the url +/washout+ and you will see a list with available services ( in our case there are only two : The RumbasController and MyOtherServiceController) with links to their documentation and where you can find the WSDL. -If you want to access directly the hml documentation that was generated for RumbasController you can do that by accessing url +/rumbas/doc+ And the WSDL will be available at +/rumbas/wsdl+ +If you want to access directly the hml documentation that was generated for RumbasController you can do that by accessing url with camelcase name +/washout/Rumbas+ or without camelcase +/washout/rumbas+ +For namespaced services you can access documentation url like this +/washout/Api::ProjectService+ or like this +/washout/api/project_service+ When specifying the soap_service you can also pass a option for description . Here is an example