Class: RooOnRails::Checks::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/roo_on_rails/checks/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#bold, included

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
24
# File 'lib/roo_on_rails/checks/base.rb', line 18

def initialize(options = {})
  @options = options.dup
  @fix     = @options.delete(:fix) { false }
  @context = @options.delete(:context) { Hashie::Mash.new }
  @shell   = @options.delete(:shell) { Shell.new }
  @dry_run = options.fetch(:dry_run, false)
end

Class Method Details

.requires(*dependencies) ⇒ Object

Add ‘dependencies` to the list of prerequisites for this check. If none are specified, return the list of dependencies.



13
14
15
16
# File 'lib/roo_on_rails/checks/base.rb', line 13

def self.requires(*dependencies)
  @requires ||= Set.new
  dependencies.any? ? @requires.merge(dependencies) : @requires
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/roo_on_rails/checks/base.rb', line 26

def run
  dependency_status = resolve dependencies

  say intro
  unless dependency_status
    final_fail! 'Unmet dependencies.'
    return
  end

  return true if @dry_run

  begin
    call
  rescue Failure
    return false unless @fix
    say "\t· attempting to fix", %i[yellow]
    fix
    @fix = false
    say "\t· re-checking", %i[yellow]
    retry
  end

  true
rescue FinalFailure
  false
end