【发布时间】:2018-05-05 06:59:38
【问题描述】:
我有一个厨师食谱名称my_recipe,我想向它添加一个库来帮助我完成一些工作,同时仍然能够顺利运行 chefspec。
我阅读了extend recipe 文档,但找不到如何在配方命名空间中扩展(或动态创建)类。
这是一个sn-p:
# my_cookbook/recipes/my_recipe.rb
foo = MyRecipe::MyClass.foo
# my_cookbook/libraries/my_class.rb
class Chef
class Recipe
class MyRecipe
unless defined?(Chef::Recipe::MyRecipe::MyClass)
class MyClass
def self.foo
# do stuff
end
end
end
end
end
end
我错过了什么?
厨师如何将 dsl 食谱名称 my_recipe 转换为食谱对象 (MyRecipe)?
【问题讨论】:
标签: ruby chef-infra chefspec