尝试在厨师食谱中包含模块时,Ruby返回未初始化的常量错误

时间:2018-10-09 17:19:54

标签: ruby chef test-kitchen

我有一个const Excel = require('exceljs'); async function copyExcel() { let targetWorkbook = new Excel.Workbook(); targetWorkbook = await targetWorkbook.xlsx.readFile('target.xlsx'); const targetWorksheet = targetWorkbook.getWorksheet('target'); // you can add new sheet as well. let sourceWorkbook = new Excel.Workbook(); sourceWorkbook = await sourceWorkbook.xlsx.readFile('source.xlsx'); const sourceWorksheet = sourceWorkbook.getWorksheet('source'); sourceWorksheet.eachRow({ includeEmpty: false }, (row, rowNumber) => { var targetRow = targetWorksheet.getRow(rowNumber); row.eachCell({ includeEmpty: false }, (cell, cellNumber) => { targetRow.getCell(cellNumber).value = cell.value; }); row.commit(); }); await targetWorkbook.xlsx.writeFile('target.xlsx'); } copyExcel(); 食谱,该食谱使用称为java/recipes/windows的方法,但由于win_friendly_path尚未定义,因此无法使用。

但是,在win_friendly_path中,

win_friendly_path的定义如下:

../windows/libraries/windows_helper.rb

我已经在module Windows module Helper def win_friendly_path(path) path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path end 食谱中设置了berksfilemetadata.rb,以取决于java (./)食谱。

我不确定如何包含此模块,所以现在我正试图在windows食谱中使用include WindowsHelper并收到此错误:

java/cookbook/windows

我尝试了几种方法,现在觉得我花了太多时间对问题进行故障排除,因此能获得任何帮助。

更新:将此行uninitialized constant #<Class:#<Chef::Recipe:0x00000000029a2188>>::WindowsHelper插入我的::Chef::Resource.send(:include, Windows::Helper)食谱会给我以下错误:

java/recipes/windows

2 个答案:

答案 0 :(得分:1)

尝试一下

include Windows::Helper

答案 1 :(得分:-1)

插入以下行为我解决了此问题:

::Chef::Recipe.send(:include, Windows::Helper)

这使我可以使用Windows食谱中以下模块中的变量:

module Windows
  module Helper
...
{Variable}
  {Other_variable}
...