Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting for disabling the plugin
The plugin can be totally skipped by setting `config.proxy.enabled` to `false` or empty string (`""`). This can be useful to for example disable it for some provider.
- Loading branch information
Showing
5 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module VagrantPlugins | ||
module ProxyConf | ||
class Action | ||
# Action which checks if the plugin should be enabled | ||
class IsEnabled | ||
def initialize(app, env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
env[:result] = plugin_enabled?(env[:machine].config.proxy) | ||
|
||
@app.call(env) | ||
end | ||
|
||
private | ||
|
||
def plugin_enabled?(config) | ||
config.enabled != false && config.enabled != '' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/action/is_enabled' | ||
|
||
describe VagrantPlugins::ProxyConf::Action::IsEnabled do | ||
let(:app) { lambda { |env| } } | ||
let(:env) { { :machine => machine } } | ||
let(:machine) do | ||
double('machine').tap { |machine| machine.stub(:config).and_return(config) } | ||
end | ||
let(:config) do | ||
double('config').tap { |config| config.stub(:proxy => proxy_config) } | ||
end | ||
let(:proxy_config) do | ||
double('proxy_config').tap { |config| config.stub(:enabled => enabled) } | ||
end | ||
|
||
[false, ''].each do |value| | ||
context "with `config.proxy.enabled=#{value.inspect}`" do | ||
let(:enabled) { value } | ||
|
||
it "results to falsy" do | ||
described_class.new(app, {}).call(env) | ||
expect(env[:result]).to be_false | ||
end | ||
end | ||
end | ||
|
||
[nil, true, :auto, 'yes please'].each do |value| | ||
context "with `config.proxy.enabled=#{value.inspect}`" do | ||
let(:enabled) { value } | ||
|
||
it "results to truthy" do | ||
described_class.new(app, {}).call(env) | ||
expect(env[:result]).to be_true | ||
end | ||
end | ||
end | ||
|
||
end |