From ed46e2e2f398d268142bc51056138ea8f2ad7b76 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 21 Jun 2016 00:23:20 +0300 Subject: [PATCH 1/4] automatically mounted engine --- lib/washout_builder/engine.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/washout_builder/engine.rb b/lib/washout_builder/engine.rb index 4a7cfa8..61364ba 100644 --- a/lib/washout_builder/engine.rb +++ b/lib/washout_builder/engine.rb @@ -2,7 +2,13 @@ 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| + if app.config.washout_builder[:mounted_path] + app.routes.append do + mount WashoutBuilder::Engine => app.config.washout_builder[:mounted_path] + end + end end end end From cd0976c7b4458f385b0a67d48df030f72d4afff9 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 21 Jun 2016 10:55:06 +0300 Subject: [PATCH 2/4] added options to blacklist or whitelist the environment where washout_builder can be mounted --- lib/washout_builder/engine.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/washout_builder/engine.rb b/lib/washout_builder/engine.rb index 61364ba..90aaebc 100644 --- a/lib/washout_builder/engine.rb +++ b/lib/washout_builder/engine.rb @@ -4,9 +4,16 @@ class Engine < ::Rails::Engine isolate_namespace WashoutBuilder config.washout_builder = ActiveSupport::OrderedOptions.new initializer 'washout_builder.configuration' do |app| - if app.config.washout_builder[:mounted_path] - app.routes.append do - mount WashoutBuilder::Engine => app.config.washout_builder[:mounted_path] + 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 From edc07ccaf1f8a7e2db1e030d7875fa2aabf50dd5 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 21 Jun 2016 11:18:47 +0300 Subject: [PATCH 3/4] readme --- README.md | 18 ++++++++++++++++++ lib/washout_builder.rb | 2 +- lib/washout_builder/version.rb | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4af9b3c..c596126 100644 --- a/README.md +++ b/README.md @@ -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 --------------------------------- diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index dc0484c..be7cba1 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -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 } diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 597e74a..252502c 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -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 From 8a85a5b628d7866ecb5d77a5e13b406631b96431 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 21 Jun 2016 11:22:34 +0300 Subject: [PATCH 4/4] readme update for mounted engine --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c596126..9511183 100644 --- a/README.md +++ b/README.md @@ -126,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 ```