【问题标题】:Monkeypatching Vagrant PluginMonkeypatching Vagrant 插件
【发布时间】:2014-12-19 19:06:26
【问题描述】:

我想对 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 无法识别补丁。少了什么东西?这种方式可以吗?

【问题讨论】:

  • 理论上是可能的。您只需要确保在修补之前首先评估您覆盖的任何内容(例如,需要该文件)。否则原件可能无法加载或覆盖您的补丁。

标签: ruby vagrant patch


【解决方案1】:

我能够像这样对其进行猴子补丁:

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

【讨论】:

    猜你喜欢
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    相关资源
    最近更新 更多