rubycanvasmoodlecommon-cartridge

Ruby canvas_cc gem is causing errors


Attempting to use the Ruby 'canvas_cc' gem to create .imscc cartridges, but running into issues that I am having difficulty trouble shooting. I followed the basic documentation in the readme, but I get an issue from within the gem.

Ruby

require 'tmpdir'
course = CanvasCc::CanvasCC::Models::Course.new
course.identifier = "cc"
course.title =  "testing cc"
dir = Dir.mktmpdir
output_dir = CanvasCc::CanvasCC::CartridgeCreator.new(course).create(dir)

Output

Traceback (most recent call last):
        5: from course_creation.rb:25:in `<main>'
        4: from /Users/me/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/canvas_cc-0.0.43/lib/canvas_cc/canvas_cc/cartridge_creator.rb:18:in `create'
        3: from /Users/me/.rbenv/versions/2.5.1/lib/ruby/2.5.0/tmpdir.rb:89:in `mktmpdir'
        2: from /Users/me/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/canvas_cc-0.0.43/lib/canvas_cc/canvas_cc/cartridge_creator.rb:19:in `block in create'
        1: from /Users/me/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/canvas_cc-0.0.43/lib/canvas_cc/canvas_cc/cartridge_creator.rb:45:in `write_cartridge'
/Users/me/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/canvas_cc-0.0.43/lib/canvas_cc/canvas_cc/grading_standard_writer.rb:11:in `write': undefined method `empty?' for nil:NilClass (NoMethodError)

Also tried

require 'canvas_cc'
course = CanvasCc::CanvasCC::Models::Course.new
course.identifier = "cc"
course.title =  "testing cc"
dir = Dir.mkdir "cartridge"
output_dir = CanvasCc::CanvasCC::CartridgeCreator.new(course).create(Dir.pwd + "/cartridge")

I am getting the same error running the second script as the first.

I've tried to understand what is wrong by looking through both the documentation and the code in the gem, but I can't seem to debug it. I am using Ruby 2.5.1 with rbenv, but I have tried multiple other ruby versions with the same issue.

My goal is to just create basic common cartridges with this gem, but I can't even do that. Any help would be much appreciated with this!


Solution

  • Just initialize this property

    course.grading_standards = []
    

    before

    output_dir = CanvasCc::CanvasCC::CartridgeCreator.new(course).create(Dir.pwd + "/cartridge")