washout_builder 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -1
- data/lib/washout_builder.rb +19 -12
- data/lib/washout_builder/engine.rb +9 -1
- data/lib/washout_builder/env_checker.rb +50 -0
- data/lib/washout_builder/version.rb +2 -2
- data/spec/app/controllers/washout_builder_controller_spec.rb +2 -2
- data/spec/lib/washout_builder/document/generator_spec.rb +10 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b50b25747f6af3feb7d0a12b37a0b6852afff0
|
4
|
+
data.tar.gz: 1db16f0e175ddfde4b33db6af4632f7296356485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa41d90617873733ec118b9e9e707904127a085ee4295640d1ebc607bb8e18ec8c4f751644f2a5ccaffd2f1e18bfba7c572fac06f667486fd9523af01d2656bb
|
7
|
+
data.tar.gz: f909f7ee2631bcec25593e46d29aa7a2acf0ff35aa88b868e605bd846d3c9e1d7bd05172e9e3af09711c6fec23af2abcdb654ee082c457c1d98b53882dc94f5f
|
data/README.md
CHANGED
@@ -10,6 +10,24 @@ 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.5.0
|
14
|
+
---------------------------------
|
15
|
+
|
16
|
+
- The WashoutBuilder::Engine can now be automatically be mounted in Rails application by using a simple configuration in **config/application.rb** which allows you to whitelist or blacklist the environment where WashoutBuilder::Engine can be mounted .
|
17
|
+
- By default all the options are set to **nil**, so the engine does not get mounted automatically by default. You need to set them if you want this to work.
|
18
|
+
|
19
|
+
E.g.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
if config.respond_to?(:washout_builder) # needed in case the gem is not in the default group
|
23
|
+
config.washout_builder.mounted_path = "/washout" # the path where the engine should be mounted on
|
24
|
+
config.washout_builder.whitelisted_envs = "*" # this can either be an array of strings or a string. If you specify "*" ,will mean all environments , otherwise you can specify "development" or ['development', 'staging'] or nil
|
25
|
+
config.washout_builder.blacklisted_envs = nil # this can either be an array of strings or a string. You can specify for example "production" or ['production', 'test'], or nil
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
If you don't set them and they are left with default nil values, you will have to use the old way, by manually mount the engine in the Rails routes configuration file (**config/routes.rb**) by following examples below.
|
30
|
+
|
13
31
|
NEW Improvements in version 1.4.0
|
14
32
|
---------------------------------
|
15
33
|
|
@@ -108,7 +126,8 @@ WashOutSample::Application.routes.draw do
|
|
108
126
|
wash_out :project_service
|
109
127
|
end
|
110
128
|
|
111
|
-
|
129
|
+
# The verfication "if defined?(WashoutBuilder::Engine)" is needed in case the "washout_builder" gem is not in the default group
|
130
|
+
mount WashoutBuilder::Engine => "/washout" if defined?(WashoutBuilder::Engine)
|
112
131
|
end
|
113
132
|
|
114
133
|
```
|
data/lib/washout_builder.rb
CHANGED
@@ -2,31 +2,38 @@ require 'wash_out'
|
|
2
2
|
require 'active_support/core_ext/object/blank'
|
3
3
|
require 'active_support/core_ext/hash/keys'
|
4
4
|
require 'active_support/concern'
|
5
|
-
require 'active_support/core_ext/string/output_safety
|
5
|
+
require 'active_support/core_ext/string/output_safety'
|
6
|
+
require 'active_support/ordered_options'
|
7
|
+
require 'active_support/core_ext/string/starts_ends_with'
|
6
8
|
|
7
9
|
Gem.find_files('washout_builder/**/*.rb').each { |path| require path }
|
8
10
|
|
9
11
|
|
10
12
|
ActionDispatch::Routing::Mapper.class_eval do
|
11
13
|
alias_method :original_wash_out, :wash_out
|
12
|
-
|
13
|
-
|
14
|
+
# Adds the routes for a SOAP endpoint at +controller+.
|
15
|
+
def wash_out(controller_name, options={})
|
16
|
+
env_checker = WashoutBuilder::EnvChecker.new(Rails.application)
|
17
|
+
if env_checker.available_for_env?(Rails.env)
|
18
|
+
options = options.symbolize_keys if options.is_a?(Hash)
|
14
19
|
if @scope
|
15
20
|
scope_frame = @scope.respond_to?(:frame) ? @scope.frame : @scope
|
16
|
-
|
21
|
+
# needed for backward compatibility with old version when this module name was camelized
|
22
|
+
options[:module] = options[:module].to_s.underscore if options[:module].present?
|
23
|
+
options.each { |key, value| scope_frame[key] = value }
|
24
|
+
controller_class_name = [scope_frame[:module], controller_name].compact.join("/").underscore
|
25
|
+
else
|
26
|
+
controller_class_name = controller_name.to_s.underscore
|
17
27
|
end
|
18
28
|
|
19
|
-
controller_class_name = [options[:module], controller_name].compact.join("/").underscore
|
20
|
-
|
21
29
|
match "#{controller_name}/soap_doc" => WashoutBuilder::Engine, via: :get,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
original_wash_out(controller_name, options)
|
30
|
+
defaults: { name: "#{controller_class_name}" },
|
31
|
+
format: false,
|
32
|
+
as: "#{controller_class_name}_soap_doc"
|
27
33
|
end
|
34
|
+
original_wash_out(controller_name, options)
|
35
|
+
end
|
28
36
|
end
|
29
|
-
|
30
37
|
# finds all the exception class and extends them by including the ExceptionModel module in order to be
|
31
38
|
# able to generate documentation for exceptions
|
32
39
|
WashoutBuilder::Type.all_fault_classes.each do |exception_class|
|
@@ -1,8 +1,16 @@
|
|
1
|
+
require_relative './env_checker'
|
1
2
|
module WashoutBuilder
|
2
3
|
# the engine that is used to mount inside the rails application
|
3
4
|
class Engine < ::Rails::Engine
|
4
5
|
isolate_namespace WashoutBuilder
|
5
|
-
|
6
|
+
config.washout_builder = ActiveSupport::OrderedOptions.new
|
7
|
+
initializer 'washout_builder.configuration' do |app|
|
8
|
+
mounted_path = app.config.washout_builder[:mounted_path]
|
9
|
+
if WashoutBuilder::EnvChecker.new(app).available_for_env?(Rails.env)
|
10
|
+
app.routes.append do
|
11
|
+
mount WashoutBuilder::Engine => mounted_path if mounted_path.is_a?(String) && mounted_path.starts_with?('/')
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
8
16
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module WashoutBuilder
|
2
|
+
class EnvChecker
|
3
|
+
|
4
|
+
attr_reader :whitelist, :blacklist
|
5
|
+
attr_writer :whitelist, :blacklist
|
6
|
+
|
7
|
+
def initialize(app)
|
8
|
+
self.whitelist = get_valid_data(app.config.washout_builder[:whitelisted_envs])
|
9
|
+
self.blacklist = get_valid_data(app.config.washout_builder[:blacklisted_envs])
|
10
|
+
end
|
11
|
+
|
12
|
+
def available_for_env?(env_name)
|
13
|
+
if (whitelist.present? || blacklist.present?)
|
14
|
+
if whitelist.find{|a| blacklist.include?(a) }.blank?
|
15
|
+
if whitelist.include?('*') || (!valid_for_env?(blacklist, env_name) && valid_for_env?(whitelist, env_name))
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
else
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def valid_for_env?(list, env_name)
|
29
|
+
try_find_suitable_env(list, env_name).present?
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_valid_data(list)
|
33
|
+
list.is_a?(Array) ? list : [list].compact
|
34
|
+
end
|
35
|
+
|
36
|
+
def try_find_suitable_env(list, env_name)
|
37
|
+
return if list.blank?
|
38
|
+
# The keys of the map can be strings or regular expressions that are
|
39
|
+
# matched against the env name and returns the found value
|
40
|
+
list.find do |env_pattern|
|
41
|
+
if env_pattern.is_a? Regexp
|
42
|
+
env_pattern.match env_name
|
43
|
+
elsif env_pattern.is_a? String
|
44
|
+
env_pattern == env_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -27,7 +27,7 @@ describe WashoutBuilder::WashoutBuilderController, type: :controller do
|
|
27
27
|
|
28
28
|
it 'gets the services' do
|
29
29
|
get :all
|
30
|
-
expect(assigns(:services)).to eq([{ 'service_name' => 'Api', 'namespace' => '/api/wsdl', 'endpoint' => '/api/action', 'documentation_url' => '
|
30
|
+
expect(assigns(:services)).to eq([{ 'service_name' => 'Api', 'namespace' => '/api/wsdl', 'endpoint' => '/api/action', 'documentation_url' => '/api/soap_doc' }])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'renders the template' do
|
@@ -43,7 +43,7 @@ describe WashoutBuilder::WashoutBuilderController, type: :controller do
|
|
43
43
|
it 'render a service documentation' do
|
44
44
|
controller.stubs(:controller_class).returns(ApiController)
|
45
45
|
controller.stubs(:controller_is_a_service?).with(params[:name]).returns(route)
|
46
|
-
WashoutBuilder::Document::Generator.expects(:new).with(route.defaults[:controller])
|
46
|
+
WashoutBuilder::Document::Generator.expects(:new).with(route, route.defaults[:controller])
|
47
47
|
get :all, params
|
48
48
|
expect(response).to render_template 'wash_with_html/doc'
|
49
49
|
end
|
@@ -29,8 +29,17 @@ describe WashoutBuilder::Document::Generator do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
let(:service_class) { ApiController }
|
32
|
+
let(:route_details) { mock }
|
33
|
+
let(:route_set) { mock }
|
34
|
+
let(:route_url_helpers) { mock }
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
route_details.stubs(:[]).with(:route_set).returns(route_set)
|
38
|
+
route_set.stubs(:url_helpers).returns(route_url_helpers)
|
39
|
+
route_url_helpers.stubs(:url_for).returns(soap_config.namespace)
|
40
|
+
end
|
32
41
|
before(:each) do
|
33
|
-
@document = WashoutBuilder::Document::Generator.new('api')
|
42
|
+
@document = WashoutBuilder::Document::Generator.new(route_details, 'api')
|
34
43
|
@document.stubs(:controller_class).returns(service_class)
|
35
44
|
end
|
36
45
|
|
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.
|
4
|
+
version: 1.5.1
|
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-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wash_out
|
@@ -368,6 +368,7 @@ files:
|
|
368
368
|
- lib/washout_builder/document/generator.rb
|
369
369
|
- lib/washout_builder/document/shared_complex_type.rb
|
370
370
|
- lib/washout_builder/engine.rb
|
371
|
+
- lib/washout_builder/env_checker.rb
|
371
372
|
- lib/washout_builder/param.rb
|
372
373
|
- lib/washout_builder/soap.rb
|
373
374
|
- lib/washout_builder/type.rb
|
@@ -480,3 +481,4 @@ test_files:
|
|
480
481
|
- spec/support/complex_types/fluffy_container.rb
|
481
482
|
- spec/support/complex_types/project_type.rb
|
482
483
|
- spec/support/complex_types/test_type.rb
|
484
|
+
has_rdoc:
|