washout_builder 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1328c1fa0594e65be4676b8297d41e56adbf698
4
- data.tar.gz: c15f894745514023201ce24c7741e95cf5d9b8f9
3
+ metadata.gz: 2b43fddeb45664fd77e68b4f381d0527f05f1b33
4
+ data.tar.gz: dcd30f9428b187356b23b67066cc45ef0061cde4
5
5
  SHA512:
6
- metadata.gz: 4875aea491dd888fa61cac8cf890a41a4d76adc598f3d87e0cbe496741aea0a59edb05aed5ed78f8e2a8644bc21360d1e74016cfc5e2d89f09aab169fc6fd2ce
7
- data.tar.gz: 4da1ad2e73e3acd3c245718fe527ceab4239ab1acb551e53d6a22ee0cdb3b815994106b825f5800af611831afdde459ef6fc9c9fed3ad1a969a2d155b84f6d4b
6
+ metadata.gz: 2e303eef7c0b1cb37fec341ff73e7aafc1e64ca749c547ba25f626990eec90d4a4e767c2ac8dfd5d1e7a46f5442d68f5b376a725fbcc203171ebcc043e6dd377
7
+ data.tar.gz: c1f6c1c75275cdf4e14176e69e8353cb6c67c499a3552f164332d34a386857051dc941fd6c2a98d8058ac58e90007c8d5e24df59b0bbc083c9ce8b6c626e01e2
data/README.md CHANGED
@@ -10,11 +10,17 @@ WashOutBuilder is a Soap Service Documentation generator (extends [WashOut](http
10
10
 
11
11
  The way [WashOut](https://github.com/inossidabile/wash_out) is used is not modified, it just extends its functionality by generating html documentation to your services that you write
12
12
 
13
+ NEW Improvements in version 1.4.0
14
+ ---------------------------------
15
+
16
+ - when displaying all services , the link to documentation is now using the new format **/soap_doc** for better readability
17
+ - Fixed an issue when generating documentation for a controller that didn't had the namespace set, the WSDL url and endpoint was missing from the generated source because of that. However if you don't set the namespace in controller the links to WSDL and endpoint would throw an error when trying to access them.
18
+
13
19
  NEW Improvements in version 1.3.0
14
20
  ---------------------------------
15
21
 
16
22
  - link to accessing documentation for a single controller is now easier. You can use the same route as for seeing WSLD, but replacing **/wsdl** with **/soap_doc**
17
- - The old way of acessing documentation is still kept, so if you mounted the engine at **/washout_builder**, you can still acess the documentation by appending to this url the full name of the controller including the namespace and the engine name(in case the controller is from a engine) as described below.
23
+ - The old way of acessing documentation is still kept, so if you mounted the engine at **/washout**, you can still acess the documentation by appending to this url the full name of the controller including the namespace and the engine name(in case the controller is from a engine) as described below.
18
24
 
19
25
  Features
20
26
  --------
@@ -15,18 +15,18 @@ module WashoutBuilder
15
15
  #
16
16
  # @api public
17
17
  def all
18
- params[:name] = params[:defaults][:name] if params[:defaults].present?
19
- find_all_routes
20
- route = params[:name].present? ? controller_is_a_service?(params[:name]) : nil
21
- if route.present? && defined?(controller_class(params[:name]))
22
- @document = WashoutBuilder::Document::Generator.new(controller_class(params[:name]).controller_path)
23
- render template: 'wash_with_html/doc', layout: false,
24
- content_type: 'text/html'
25
- elsif
26
- @services = all_services
27
- render template: 'wash_with_html/all_services', layout: false,
28
- content_type: 'text/html'
29
- end
18
+ params[:name] = params[:defaults][:name] if params[:defaults].present?
19
+ find_all_routes
20
+ route_details = params[:name].present? ? controller_is_a_service?(params[:name]) : nil
21
+ if route_details.present? && defined?(controller_class(params[:name]))
22
+ @document = WashoutBuilder::Document::Generator.new(route_details, controller_class(params[:name]).controller_path)
23
+ render template: 'wash_with_html/doc', layout: false,
24
+ content_type: 'text/html'
25
+ elsif
26
+ @services = all_services
27
+ render template: 'wash_with_html/all_services', layout: false,
28
+ content_type: 'text/html'
29
+ end
30
30
  end
31
31
 
32
32
  private
@@ -45,17 +45,24 @@ module WashoutBuilder
45
45
  #
46
46
  # @api private
47
47
  def all_services
48
- @map_controllers = map_controllers { |route| route.defaults[:controller] }
49
- @map_controllers.blank? ? [] : @map_controllers.map do |controller_name|
50
- {
51
- 'service_name' => controller_naming(controller_name),
52
- 'namespace' => service_namespace(controller_name),
53
- 'endpoint' => service_endpoint(controller_name),
54
- 'documentation_url' => service_documentation_url(controller_name)
55
- }
48
+ @map_controllers = map_controllers { |hash| hash }
49
+ @map_controllers.blank? ? [] : @map_controllers.map do |hash|
50
+ controller_name = hash[:route].present? && hash[:route].respond_to?(:defaults) ? hash[:route].defaults[:controller] : nil
51
+ if controller_name.present?
52
+ {
53
+ 'service_name' => controller_naming(controller_name),
54
+ 'namespace' => service_namespace(hash, controller_name),
55
+ 'endpoint' => service_endpoint(hash, controller_name),
56
+ 'documentation_url' => service_documentation_url(hash, controller_name)
57
+ }
58
+ end
56
59
  end
57
60
  end
58
61
 
62
+ def generate_wsdl_action
63
+ '_generate_wsdl'
64
+ end
65
+
59
66
  # the way of converting from controller string in downcase in camelcase
60
67
  # @param [String] controller The controller name in downcase letter
61
68
  #
@@ -73,18 +80,30 @@ module WashoutBuilder
73
80
  #
74
81
  # @api private
75
82
  def route_can_generate_wsdl?(route)
76
- route.defaults[:action] == '_generate_wsdl'
83
+ route.defaults[:action] == generate_wsdl_action
77
84
  end
78
85
 
79
86
  def find_all_routes
80
- rails_routes = Rails.application.routes.routes.map { |route| route }
81
- engine_routes = []
82
- ::Rails::Engine.subclasses.each do |engine|
83
- engine.routes.routes.each do |route|
84
- engine_routes << route
85
- end
87
+ # get the controller and set the action for redirection
88
+ engines = [Rails.application]
89
+ engines.concat(::Rails::Engine.subclasses)
90
+
91
+ routes = engines.each_with_object([]) do |engine, routes_array|
92
+ engine_route = Rails.application.routes.named_routes[engine.engine_name]
93
+ routes_hash_array = engine.routes.routes.map { |route|
94
+ {
95
+ engine: engine,
96
+ route_set: engine.routes,
97
+ route: route,
98
+ mounted_at: engine_route.blank? ? nil : engine_route.path.spec.to_s
99
+ }
100
+ }
101
+
102
+ routes_array.concat(routes_hash_array)
86
103
  end
87
- @routes = rails_routes.concat(engine_routes).uniq.compact
104
+
105
+ #routes = routes.sort_by { |hash| hash[:route].precedence }
106
+ @routes = routes
88
107
  @routes
89
108
  end
90
109
 
@@ -99,13 +118,13 @@ module WashoutBuilder
99
118
  # @return [ActionDispatch::Journey::Route, Array<ActionDispatch::Journey::Route>] Can return either a collection of routes or a single route depending on the action
100
119
  #
101
120
  # @api private
102
- def map_controllers(action = 'map')
103
- res = @routes.send(action) do |route|
104
- if route_can_generate_wsdl?(route)
105
- yield route if block_given?
121
+ def map_controllers(action = 'select')
122
+ res = @routes.send(action) do |hash|
123
+ if hash[:route].present? && route_can_generate_wsdl?(hash[:route])
124
+ yield hash if hash.present? && block_given?
106
125
  end
107
126
  end
108
- res = res.uniq.compact if action == 'map'
127
+ res = res.compact.uniq{|hash| hash[:route] } if action == 'select'
109
128
  res
110
129
  end
111
130
 
@@ -119,8 +138,10 @@ module WashoutBuilder
119
138
  #
120
139
  # @api private
121
140
  def controller_is_a_service?(controller)
122
- map_controllers('detect') do |route|
123
- controller_naming(route.defaults[:controller]) == controller_naming(controller)
141
+ map_controllers('detect') do |hash|
142
+ if hash[:route].present? && hash[:route].respond_to?(:defaults)
143
+ controller_naming(hash[:route].defaults[:controller]) == controller_naming(controller)
144
+ end
124
145
  end
125
146
  end
126
147
 
@@ -135,6 +156,10 @@ module WashoutBuilder
135
156
  controller_naming("#{controller}_controller").constantize
136
157
  end
137
158
 
159
+ def route_helpers(hash)
160
+ hash[:route_set].url_helpers
161
+ end
162
+
138
163
  # retrieves the service namespace
139
164
  # @see #controller_class
140
165
  #
@@ -146,8 +171,9 @@ module WashoutBuilder
146
171
  # @return [String] The namespace of the soap service that is used in that controller
147
172
  #
148
173
  # @api private
149
- def service_namespace(controller_name)
150
- controller_class(controller_name).soap_config.namespace
174
+ def service_namespace(hash, controller_name)
175
+ #controller_class(controller_name).soap_config.namespace
176
+ route_helpers(hash).url_for(controller: controller_name, action: generate_wsdl_action, only_path: true)
151
177
  end
152
178
 
153
179
  # the endpoint is based on the namespace followed by /action suffix
@@ -156,8 +182,8 @@ module WashoutBuilder
156
182
  # @param [String] controller_name The name of the controller
157
183
  # @return [String] The endpoint of the web service
158
184
  # @api private
159
- def service_endpoint(controller_name)
160
- service_namespace(controller_name).gsub('/wsdl', '/action')
185
+ def service_endpoint(hash, controller_name)
186
+ service_namespace(hash, controller_name).gsub('/wsdl', '/action')
161
187
  end
162
188
 
163
189
  # constructs the documentation url for a specific web service
@@ -165,9 +191,9 @@ module WashoutBuilder
165
191
  # @param [String] controller_name The name of the controller
166
192
  # @return [String] The documentation url for the web service ( relative to base url)
167
193
  # @api private
168
- def service_documentation_url(controller_name)
169
- #service_namespace(controller_name).gsub('/wsdl', '/soap_doc')
170
- "#{washout_builder.root_url}#{controller_naming(controller_name)}"
194
+ def service_documentation_url(hash, controller_name)
195
+ service_namespace(hash, controller_name).gsub('/wsdl', '/soap_doc')
196
+ #"#{washout_builder.root_path}#{controller_naming(controller_name)}"
171
197
  end
172
198
  end
173
199
  end
@@ -34,13 +34,16 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
34
34
  xml.h1 "#{ @document.service} Soap WebService interface description"
35
35
 
36
36
  xml.p{ |y| y << "Endpoint URI:";
37
- xml.span( "class" => "pre") { |y| y << "#{@document.endpoint}"};
37
+ xml.span( "class" => "pre") {
38
+ xml.a( "href" => "#{@document.endpoint}") { |y| y << "#{@document.endpoint}" }
39
+ };
38
40
  }
39
41
 
40
42
  xml.p{ |y| y << "WSDL URI:";
41
43
  xml.span( "class" => "pre") {
42
44
  xml.a( "href" => "#{@document.namespace}") { |y| y << "#{@document.namespace}" }
43
- };}
45
+ };
46
+ }
44
47
  xml.p ""
45
48
  unless @document.service_description.blank?
46
49
  xml.p "#{@document.service_description}"
@@ -13,7 +13,7 @@ module WashoutBuilder
13
13
  #
14
14
  # @!attribute controller_name
15
15
  # @return [String] The name of the controller that acts like a soap service
16
- attr_accessor :soap_actions, :config, :controller_name
16
+ attr_accessor :soap_actions, :config, :controller_name, :route_details
17
17
 
18
18
  # Method used to initialize the instance of object
19
19
  # @see #controller_class
@@ -21,19 +21,24 @@ module WashoutBuilder
21
21
  # @param [String] controller The name of the controller that acts like a soap service
22
22
  # @return [void]
23
23
  # @api public
24
- def initialize(controller)
24
+ def initialize(route_details, controller)
25
+ self.route_details = route_details
25
26
  controller_class_name = controller_class(controller)
26
27
  self.config = controller_class_name.soap_config
27
28
  self.soap_actions = controller_class_name.soap_actions
28
29
  self.controller_name = controller
29
30
  end
30
31
 
32
+ def controller_route_helpers
33
+ route_details[:route_set].url_helpers
34
+ end
35
+
31
36
  # Returns the namespace used for the controller by using the soap configuration of the controller
32
37
  #
33
38
  # @return [String] description of returned object
34
39
  # @api public
35
40
  def namespace
36
- config.respond_to?(:namespace) ? config.namespace : nil
41
+ controller_route_helpers.url_for(controller: controller_name, action: "_generate_wsdl", only_path: true)
37
42
  end
38
43
 
39
44
  # Retrives the class of the controller by using its name
@@ -10,7 +10,7 @@ module WashoutBuilder
10
10
  # the major version of the gem
11
11
  MAJOR = 1
12
12
  # the minor version of the gem
13
- MINOR = 3
13
+ MINOR = 4
14
14
  # the tiny version of the gem
15
15
  TINY = 0
16
16
  # if the version should be a e
@@ -41,7 +41,8 @@ describe WashoutBuilder::WashoutBuilderController, type: :controller do
41
41
  end
42
42
 
43
43
  it 'render a service documentation' do
44
- controller.expects(:controller_is_a_service?).with(params[:name]).returns(route)
44
+ controller.stubs(:controller_class).returns(ApiController)
45
+ controller.stubs(:controller_is_a_service?).with(params[:name]).returns(route)
45
46
  WashoutBuilder::Document::Generator.expects(:new).with(route.defaults[:controller])
46
47
  get :all, params
47
48
  expect(response).to render_template 'wash_with_html/doc'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: washout_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wash_out
@@ -480,4 +480,3 @@ test_files:
480
480
  - spec/support/complex_types/fluffy_container.rb
481
481
  - spec/support/complex_types/project_type.rb
482
482
  - spec/support/complex_types/test_type.rb
483
- has_rdoc: