barby
barby copied to clipboard
Rmagick Outputter Deprecation Warning
I keep on getting the following warning message:
/home/alexander/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/barby-0.6.8/lib/barby/outputter/rmagick_outputter.rb:56: warning: passing a block without an image argument is deprecated
The code that this error arises from:
#Returns an instance of Magick::Image
def to_image(opts={})
with_options opts do
b = background #Capture locally because Magick::Image.new block uses instance_eval
canvas = Magick::Image.new(full_width, full_height){ self.background_color = b }
...
My code:
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/ascii_outputter'
require 'barby/outputter/html_outputter'
require 'barby/outputter/rmagick_outputter'
class BarcodeGenerator
def self.generate_barcode_for_lumber_unit(lumber_unit)
barcode = Barby::Code128B.new(lumber_unit.uuid)
outputter = Barby::RmagickOutputter.new(barcode)
filename = "barcode_#{DateTime.now.strftime('%Y%m%d%H%M%S%L')}.png"
filepath = "app/assets/images/#{filename}"
f = File.open(filepath, 'wb')
f.write(outputter.to_png(height: 50))
f.close
lumber_unit.barcode.attach(io: File.open(filepath), filename:)
lumber_unit.save!
end
end
The line that raises this error:
f.write(outputter.to_png(height: 50))
Can anyone suggest how I might amend my code to stop raising the deprecation warning? I scrutinised the documentation here but I couldn't work it out.
@panhandledoor This isn't a you problem, it's a gem problem. I've added a PR here:
https://github.com/toretore/barby/pull/113
That said, I'm pretty sure this gem is no longer maintained by the author, and every other fork of it I've seen is equally ghosted. For what it's worth, the deprecation warning doesn't appear to be hurting anything, so if you can live with the annoyance, you're probably fine.
Beyond that, feel free to use my fork, (which has the fix), or fork it yourself and apply the fix, blah blah blah open source, etc. 😁