Skip to content

Commit

Permalink
Merge branch 'feature/automatically-mounted-engine' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Jun 21, 2016
2 parents f6efd8d + 8a85a5b commit c1c3901
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ WashOutBuilder is a Soap Service Documentation generator (extends [WashOut](http

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

NEW Improvements in version 1.5.0
---------------------------------

- 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 .
- 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.

E.g.

```ruby
if config.respond_to?(:washout_builder) # needed in case the gem is not in the default group
config.washout_builder.mounted_path = "/washout" # the path where the engine should be mounted on
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
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
end
```

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.

NEW Improvements in version 1.4.0
---------------------------------

Expand Down Expand Up @@ -108,7 +126,8 @@ WashOutSample::Application.routes.draw do
wash_out :project_service
end

mount WashoutBuilder::Engine => "/washout"
# The verfication "if defined?(WashoutBuilder::Engine)" is needed in case the "washout_builder" gem is not in the default group
mount WashoutBuilder::Engine => "/washout" if defined?(WashoutBuilder::Engine)
end

```
Expand Down
2 changes: 1 addition & 1 deletion lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/keys'
require 'active_support/concern'
require 'method_source'
require 'active_support/core_ext/string/output_safety.rb'
require 'active_support/ordered_options'

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

Expand Down
15 changes: 14 additions & 1 deletion lib/washout_builder/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ module WashoutBuilder
# the engine that is used to mount inside the rails application
class Engine < ::Rails::Engine
isolate_namespace WashoutBuilder
initializer 'washout_builder.configuration' do |_app|
config.washout_builder = ActiveSupport::OrderedOptions.new
initializer 'washout_builder.configuration' do |app|
blacklisted_envs = app.config.washout_builder[:blacklisted_envs]
blacklisted_envs = blacklisted_envs.is_a?(Array) ? blacklisted_envs : [blacklisted_envs].compact
whitelisted_envs = app.config.washout_builder[:whitelisted_envs]
whitelisted_envs = whitelisted_envs.is_a?(Array) ? whitelisted_envs : [whitelisted_envs].compact
mounted_path = app.config.washout_builder[:mounted_path]
if (whitelisted_envs.present? || blacklisted_envs.present?) && whitelisted_envs.find{|a| blacklisted_envs.include?(a) }.blank?
if whitelisted_envs.include?('*') || (!blacklisted_envs.include?(Rails.env) || whitelisted_envs.include?(Rails.env))
app.routes.append do
mount WashoutBuilder::Engine => mounted_path if mounted_path.is_a?(String) && mounted_path.starts_with?('/')
end
end
end
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 = 4
MINOR = 5
# the tiny version of the gem
TINY = 3
TINY = 0
# if the version should be a e
PRE = nil

Expand Down

0 comments on commit c1c3901

Please sign in to comment.