gpt4 book ai didi

ruby - Monkeypatching Vagrant 插件

转载 作者:数据小太阳 更新时间:2023-10-29 08:12:07 24 4
gpt4 key购买 nike

我想用 monkeypatch 一个 Vagrant 插件。

由于我不是 Ruby 专家,但想测试一些行为,所以我需要一些帮助。

我需要重写 chef_provisioner? 方法: https://github.com/fgrehm/vagrant-cachier/blob/master/lib/vagrant-cachier/cap/linux/chef_file_cache_path.rb

这就是我目前在 Vagrantfile 顶部得到的内容:

module VagrantPlugins
module Cachier
module Cap
module Linux
module ChefFileCachePath
def self.chef_provisioner?(machine)
# patch applies here
end
end
end
end
end
end

Vagrant 无法识别补丁。缺少了什么?这样可行吗?

最佳答案

我能够像这样对其进行 monkeypatch:

module VagrantPlugins
module Cachier
module Cap
module Linux
module ChefFileCachePath
def self.chef_provisioner?(machine)
# stuff
end
def self.chef_file_cache_path(machine)
# other method stuff
end
end
end
end
end
end

VagrantPlugins::Cachier::Plugin.guest_capability 'linux', 'chef_file_cache_path' do
# load the patched module
VagrantPlugins::Cachier::Cap::Linux::ChefFileCachePath
end

关于ruby - Monkeypatching Vagrant 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27572392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com