使用 capistrano 3 自定义输出
Custom output with capistrano 3
我需要更改使用 sshkit 格式化程序生成的输出,我无法安装额外的 gem,但我可以调整我的 capistrano 3 配置。起初我尝试只创建新的格式化程序(我只是复制粘贴漂亮的格式化程序,并进行了一些输出更改)。像这样 https://gist.github.com/Dariusp/3e455fdb78b9f8636289
比 deploy.rb 文件中的 set :format, :improvedformatter
。并添加
require_relative 'lib/improved_formatter'
到 Capfile。
但我总是收到错误消息“不应直接使用抽象格式化程序,也许你想要 SSHKit::Formatter::BlackHole”,就像我正在尝试直接使用抽象格式化程序一样。如果我尝试扩展 PrettyFormater,我会得到 PrettyFormatter 输出,而无需我的更改。它似乎总是执行父 class 方法。有什么方法可以在我的 capistrano 配置中创建和设置自定义格式化程序吗?
我 运行 当我想覆盖漂亮的格式化程序时遇到了完全相同的问题。
问题是我还需要定义“<<”运算符,因为它被定义为基础 class 中的别名,并且不会继承别名。
在deploy.rb中:
set :format, :myformatter
在 Capfile 中:
require 'lib/sshkit/formatters/myformatter'
在 lib/sshkit/formatters/myformatter.rb:
module SSHKit
module Formatter
class MyFormatter < Pretty
def <<(obj)
write(obj)
end
def write(obj)
...
end
end
end
end
我需要更改使用 sshkit 格式化程序生成的输出,我无法安装额外的 gem,但我可以调整我的 capistrano 3 配置。起初我尝试只创建新的格式化程序(我只是复制粘贴漂亮的格式化程序,并进行了一些输出更改)。像这样 https://gist.github.com/Dariusp/3e455fdb78b9f8636289
比 deploy.rb 文件中的 set :format, :improvedformatter
。并添加
require_relative 'lib/improved_formatter'
到 Capfile。 但我总是收到错误消息“不应直接使用抽象格式化程序,也许你想要 SSHKit::Formatter::BlackHole”,就像我正在尝试直接使用抽象格式化程序一样。如果我尝试扩展 PrettyFormater,我会得到 PrettyFormatter 输出,而无需我的更改。它似乎总是执行父 class 方法。有什么方法可以在我的 capistrano 配置中创建和设置自定义格式化程序吗?
我 运行 当我想覆盖漂亮的格式化程序时遇到了完全相同的问题。 问题是我还需要定义“<<”运算符,因为它被定义为基础 class 中的别名,并且不会继承别名。
在deploy.rb中:
set :format, :myformatter
在 Capfile 中:
require 'lib/sshkit/formatters/myformatter'
在 lib/sshkit/formatters/myformatter.rb:
module SSHKit
module Formatter
class MyFormatter < Pretty
def <<(obj)
write(obj)
end
def write(obj)
...
end
end
end
end