Module: SnapDiff::Driver

Included in:
SnapDiff::Drivers::ChunkyPNGDriver, SnapDiff::Drivers::VipsDriver
Defined in:
lib/snap_diff/driver.rb

Overview

Shared default behavior for image-processing drivers.

Replaces the old Capybara::Screenshot::Diff::Drivers::BaseDriver superclass (ADR-004 v2 step 4): concrete drivers include Driver instead of inheriting. Method names are intentionally unchanged from v1 — see dissent #4 in the v2 architecture design.

Constant Summary collapse

PNG_EXTENSION =
".png"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Including this mixin is what makes a custom driver a driver, so it is where a custom-driver author can be told that 2.1 removes the whole abstraction. Scoped to drivers that are NOT the gem's own two: both bundled drivers include it themselves, and warning there would fire on every plain vips setup -- about code the user does not own.



20
21
22
23
24
25
26
27
28
29
# File 'lib/snap_diff/driver.rb', line 20

def self.included(base)
  return if base.name.to_s.start_with?("SnapDiff::")

  Removal.warn_once(
    :driver_mixin,
    "`include SnapDiff::Driver` (in #{base.name || base.inspect}) is REMOVED in 2.1: the " \
    "driver abstraction goes away and libvips becomes the only backend, so custom drivers " \
    "stop working. There is no replacement -- see docs/drivers.md."
  )
end

Instance Method Details

#dimension(image) ⇒ Object



47
48
49
# File 'lib/snap_diff/driver.rb', line 47

def dimension(image)
  [width_for(image), height_for(image)]
end

#height_for(image) ⇒ Object



35
36
37
# File 'lib/snap_diff/driver.rb', line 35

def height_for(image)
  image.height
end

#image_area_size(image) ⇒ Object



43
44
45
# File 'lib/snap_diff/driver.rb', line 43

def image_area_size(image)
  width_for(image) * height_for(image)
end

#same_dimension?(comparison) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/snap_diff/driver.rb', line 31

def same_dimension?(comparison)
  dimension(comparison.base_image) == dimension(comparison.new_image)
end

#supports?(feature) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/snap_diff/driver.rb', line 51

def supports?(feature)
  respond_to?(feature)
end

#width_for(image) ⇒ Object



39
40
41
# File 'lib/snap_diff/driver.rb', line 39

def width_for(image)
  image.width
end