Module: SnapDiff::Utils

Defined in:
lib/snap_diff/utils.rb

Constant Summary collapse

CHUNKY_PNG_REMOVED =

THE selection funnel. Every surface that picks a driver ends up here -- driver: :chunky_png per comparison, SnapDiff.config.driver =, the legacy Diff.driver = (a delegator onto the same storage), and :auto -- so this is the one place the chunky_png removal has to be announced from. Warned before the registry lookup, not inside it: the cache is a ||=, so a hook there would fire only for the first comparison of a process that happened to miss.

"The chunky_png driver is REMOVED in 2.1, when libvips (the `ruby-vips` gem) becomes " \
"required. Install ruby-vips and drop `driver: :chunky_png`. See docs/drivers.md."
CHUNKY_PNG_AUTO_REMOVED =

The case that matters most: nobody asked for this driver, so the warning has to say why they are on it.

"`driver: :auto` selected chunky_png because libvips is not available in this process. " \
"The chunky_png driver is REMOVED in 2.1, when libvips (the `ruby-vips` gem) becomes " \
"required -- install it now, or this setup stops comparing on 2.1. See docs/drivers.md."

Class Method Summary collapse

Class Method Details

.detect_available_driversObject

Detection itself lives on Drivers now (its canonical home -- so that require "snap_diff/drivers" standalone can answer .available); this keeps the documented Utils name working. One-way: Drivers never calls back here at load time, so requiring either file first is safe.



30
31
32
# File 'lib/snap_diff/utils.rb', line 30

def self.detect_available_drivers
  Drivers.detect_available
end

.find_driver_class_for(driver) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/snap_diff/utils.rb', line 34

def self.find_driver_class_for(driver)
  if driver == :auto
    # Drivers::AVAILABLE_DRIVERS, not Drivers.available: same value and
    # the same stubbing point, without the gem tripping .available's own
    # removal warning on every comparison.
    driver = Drivers::AVAILABLE_DRIVERS.first
    Removal.warn_once(:chunky_png_auto, CHUNKY_PNG_AUTO_REMOVED) if driver == :chunky_png
  elsif driver == :chunky_png
    Removal.warn_once(:chunky_png, CHUNKY_PNG_REMOVED)
  end

  Drivers.registry[driver] ||=
    case driver
    when :chunky_png
      require "snap_diff/drivers/chunky_png_driver"
      SnapDiff::Drivers::ChunkyPNGDriver
    when :vips
      require "snap_diff/drivers/vips_driver"
      SnapDiff::Drivers::VipsDriver
    else
      fail "Wrong adapter #{driver.inspect}. Available adapters: #{Drivers::AVAILABLE_DRIVERS.inspect}"
    end
end