mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Add extension mechanism for custom ST operations
git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3604 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3ff7518348
commit
e4f56866aa
4 changed files with 57 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*0.11.0* *SVN*
|
||||
|
||||
* Add extension mechanism for custom ST operations
|
||||
|
||||
* Make ST rails rake tasks more configurable
|
||||
|
||||
* Add Actor#current_task and simplify Task#servers
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'switchtower/actor'
|
||||
require 'switchtower/logger'
|
||||
require 'switchtower/scm/subversion'
|
||||
require 'switchtower/extensions'
|
||||
|
||||
module SwitchTower
|
||||
# Represents a specific SwitchTower configuration. A Configuration instance
|
||||
|
|
38
lib/switchtower/extensions.rb
Normal file
38
lib/switchtower/extensions.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'switchtower/actor'
|
||||
|
||||
module SwitchTower
|
||||
class ExtensionProxy
|
||||
def initialize(actor, mod)
|
||||
@actor = actor
|
||||
extend(mod)
|
||||
end
|
||||
|
||||
def method_missing(sym, *args, &block)
|
||||
@actor.send(sym, *args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
EXTENSIONS = {}
|
||||
|
||||
def self.plugin(name, mod)
|
||||
return false if EXTENSIONS.has_key?(name)
|
||||
|
||||
SwitchTower::Actor.class_eval <<-STR, __FILE__, __LINE__+1
|
||||
def #{name}
|
||||
@__#{name}_proxy ||= SwitchTower::ExtensionProxy.new(self, SwitchTower::EXTENSIONS[#{name.inspect}])
|
||||
end
|
||||
STR
|
||||
|
||||
EXTENSIONS[name] = mod
|
||||
return true
|
||||
end
|
||||
|
||||
def self.remove_plugin(name)
|
||||
if EXTENSIONS.delete(name)
|
||||
SwitchTower::Actor.send(:remove_method, name)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
|
@ -84,6 +84,12 @@ class ActorTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
module CustomExtension
|
||||
def do_something_extra(a, b, c)
|
||||
run "echo '#{a} :: #{b} :: #{c}'"
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
TestingCommand.reset!
|
||||
@actor = TestActor.new(MockConfiguration.new)
|
||||
|
@ -275,4 +281,14 @@ class ActorTest < Test::Unit::TestCase
|
|||
|
||||
assert_raises(RuntimeError) { @actor.foo }
|
||||
end
|
||||
|
||||
def test_custom_extension
|
||||
assert SwitchTower.plugin(:custom, CustomExtension)
|
||||
@actor.define_task :foo, :roles => :db do
|
||||
custom.do_something_extra(1, 2, 3)
|
||||
end
|
||||
assert_nothing_raised { @actor.foo }
|
||||
assert TestingCommand.invoked?
|
||||
assert SwitchTower.remove_plugin(:custom)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue