Module: SanePatch

Defined in:
lib/sane_patch.rb,
lib/sane_patch/version.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.patch(gem_name, *requirements, details: nil) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sane_patch.rb', line 9

def self.patch(gem_name, *requirements, details: nil)
  gem_spec = Gem.loaded_specs[gem_name]
  raise Errors::GemAbsent, "Can't patch unloaded gem #{gem_name}" unless gem_spec

  gem_requirement = Gem::Requirement.create(requirements)
  if gem_requirement.satisfied_by?(gem_spec.version)
    yield
  else
    message = <<~ERROR
      It looks like the #{gem_name} gem was upgraded.
      There are patches in place that need to be verified.
      Make sure that the patch at #{caller_locations.first} is still needed and working.
    ERROR
    message += "Details:\n#{details}" if details

    raise Errors::IncompatibleVersion, message
  end
end