ruby - Chef 13 中 method_missing 的替代方法
问题描述
将系统从厨师 12 升级到 13 面临 method_missing 的问题,从一些链接中发现 method_missing 已被弃用,是否有任何替代方法。
def method_missing(name, *args, &block)
# Build the set of names to check for a valid resource
lookup_path = ["application_#{name}"]
run_context.cookbook_collection.each do |cookbook_name, cookbook_ver|
if cookbook_name.start_with?("application_")
lookup_path << "#{cookbook_name}_#{name}"
end
end
lookup_path << name
resource = nil
lookup_path = ["application_#{name}"]
# Try to find our resource
lookup_path.each do |resource_name|
begin
Chef::Log.debug "Trying to load application resource #{resource_name} for #{name}"
resource = super(resource_name.to_sym, *args, &block)
break
rescue NameError => e
# Works on any MRI ruby
if e.name == resource_name.to_sym || e.inspect =~ /\b#{resource_name}\b/
next
else
raise e
end
end
end
raise NameError, "No resource found for #{name}. Tried #{lookup_path.join(', ')}" unless resource
# Enforce action :nothing in case people forget
resource.action :nothing
# Make this a weakref to prevent a cycle between the application resource and the sub resources
resource.application WeakRef.new(self)
resource.type name
@sub_resources << resource
resource
end
解决方案
啊,我在评论中看到了真正的问题。application_php 说明书从未升级为与较新的应用说明书套件的其余部分一起使用。您必须编写自己的版本。
对于通过谷歌找到这个问题的其他人:这method_missing
件事完全是红鲱鱼。用户很困惑,因为在 Chef 中我们删除了method_missing
基于 - 的节点属性语法。这与我将其用于子资源管理无关。
推荐阅读
- square - Square Point of Sale - 不匹配的 client_id 不引发错误
- sql-server - 如何更改 DB-Visualizer 中的边框颜色?
- python - 动态创建类成员 sqlalchemy
- ruby-on-rails - 在 RoR 上的黄瓜测试中转到正确页面时出错
- javascript - 来自 React 材质 UI MenuItem 单击事件的 setState
- java - java/android - TimeZone 的一致方式 3 字母缩写
- mongoose - 如何打印出嵌套在猫鼬模式中的对象?
- java - 无法打开 ServletContext 资源 [/WEB-INF/dispatcher-servlet.xml]
- php - 如何检查管理员是否在自定义 php 文件中登录?
- python - 为什么 Python 的 strptime() 允许“秒”为 60 和 61?