1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Implementation of remove.

This commit is contained in:
William Johnston 2016-02-23 21:18:51 -06:00
parent 8f9f0f02dd
commit a4227f330a
4 changed files with 39 additions and 2 deletions

View file

@ -6,6 +6,7 @@ Reverse Chronological Order:
https://github.com/capistrano/capistrano/compare/v3.4.0...HEAD
* `remove` DSL method for removing values like from arrays like `linked_dirs`
* `append` DSL method for pushing values like `linked_dirs`
[#1447](https://github.com/capistrano/capistrano/pull/1447),
[#1586](https://github.com/capistrano/capistrano/pull/1586)

View file

@ -28,7 +28,7 @@ module Capistrano
def set(key, value=nil, &block)
invoke_validations(key, value, &block)
config[key] = block || value
puts "Config variable set: #{key.inspect} => #{config[key].inspect}" if fetch(:print_config_variables, false)
config[key]
@ -42,6 +42,10 @@ module Capistrano
set(key, Array(fetch(key)).concat(values))
end
def remove(key, *values)
set(key, Array(fetch(key)) - values)
end
def delete(key)
config.delete(key)
end

View file

@ -6,7 +6,7 @@ module Capistrano
extend Forwardable
def_delegators :env,
:configure_backend, :fetch, :set, :set_if_empty, :delete,
:ask, :role, :server, :primary, :validate, :append
:ask, :role, :server, :primary, :validate, :append, :remove
def is_question?(key)
env.is_question?(key)

View file

@ -175,6 +175,38 @@ module Capistrano
end
end
end
context 'removing' do
before :each do
config.set(:linked_dirs, ['vendor/bundle', 'tmp'])
end
subject { config.remove(:linked_dirs, 'vendor/bundle') }
it 'returns without removed value' do
expect(subject).to eq ['tmp']
end
context 'on non-array variable' do
before { config.set(:linked_dirs, 'string') }
context 'when removing same value' do
subject { config.remove(:linked_dirs, 'string') }
it 'returns without removed value' do
expect(subject).to eq []
end
end
context 'when removing different value' do
subject { config.remove(:linked_dirs, 'othervalue') }
it 'returns without removed value' do
expect(subject).to eq ['string']
end
end
end
end
end
describe 'keys' do