class Patches::Runner

Attributes

path[RW]

Public Class Methods

new(path = nil) click to toggle source
# File lib/patches/runner.rb, line 6
def initialize(path = nil)
  @path = path || Patches.default_path
end

Public Instance Methods

complete!(patch_path) click to toggle source
# File lib/patches/runner.rb, line 27
def complete!(patch_path)
  Patches::Patch.create!(path: patch_path)
end
format_exception(e) click to toggle source
# File lib/patches/runner.rb, line 39
def format_exception(e)
  "#{e.class.name}: #{e.message} (#{e.backtrace.first})"
end
patch_path(patch_path) click to toggle source
# File lib/patches/runner.rb, line 31
def patch_path(patch_path)
  File.basename(patch_path)
end
pending() click to toggle source
# File lib/patches/runner.rb, line 35
def pending
  @pending ||= Patches::Pending.new(path)
end
perform() click to toggle source
# File lib/patches/runner.rb, line 10
def perform
  completed_patches = pending.each do |file_path|
    klass = load_class(file_path)
    instance = klass.new
    Patches.logger.info("Running #{klass} from #{file_path}")
    begin
      instance.run
    rescue => e
      Patches::Notifier.notify_failure(file_path, format_exception(e))
      raise e
    end
    complete!(patch_path(file_path))
  end
  Patches::Notifier.notify_success(completed_patches)
  completed_patches
end

Private Instance Methods

load_class(path) click to toggle source
# File lib/patches/runner.rb, line 44
def load_class(path)
  begin
    name = Patches.class_name(path)
    load path
    name.constantize
  rescue StandardError, LoadError
    raise UnknownPatch, "#{path} should define #{name}"
  end
end