class Boxen::Check

The superclass for preflight and postflight sanity checks.

Attributes

config[R]

Public Class Methods

checks(config) click to toggle source

A collection of preflight instances for `config`. An instance is created for every constant under `self` that's also a subclass of `self`.

# File lib/boxen/check.rb, line 13
def self.checks(config)
  constants.map { |n| const_get n }.
    select { |c| c < self }.
    map { |c| c.new config }
end
new(config) click to toggle source
# File lib/boxen/check.rb, line 33
def initialize(config)
  @config = config
end
register(dir) click to toggle source

Search `dir` and load all Ruby files under it.

# File lib/boxen/check.rb, line 21
def self.register(dir)
  Dir["#{dir}/*.rb"].sort.each { |f| load f }
end
run(config) click to toggle source

Check each instance against `config`.

# File lib/boxen/check.rb, line 27
def self.run(config)
  checks(config).each { |check| check.run unless check.ok? }
end

Public Instance Methods

abort(message, *extras) click to toggle source

A fancier `abort` and `warn`. This will probably really annoy someone at some point because it's overriding a Kernel method, but it's limited to checks.

# File lib/boxen/check.rb, line 53
def abort(message, *extras)
  extras << { :color => :red }
  warn message, *extras
  exit 1
end
ok?() click to toggle source

Is everything good to go? Implemented by subclasses.

# File lib/boxen/check.rb, line 39
def ok?
  raise "Subclasses must implement this method."
end
run() click to toggle source

Warn, fix, or abort. Implemented by subclasses.

# File lib/boxen/check.rb, line 45
def run
  raise "Subclasses must implement this method."
end
warn(message, *extras) click to toggle source
# File lib/boxen/check.rb, line 59
def warn(message, *extras)
  options = Hash === extras.last ? extras.pop : {}
  color   = options[:color] || :yellow

  $stderr.puts ANSI.send(color) { "--> #{message}" }

  unless extras.empty?
    extras.each { |line| $stderr.puts "    #{line}" }
  end

  $stderr.puts
end