Class: Boxen::Check
- Inherits:
-
Object
- Object
- Boxen::Check
- Defined in:
- lib/boxen/check.rb
Overview
The superclass for preflight and postflight sanity checks.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.checks(config) ⇒ Object
A collection of preflight instances for ‘config`.
-
.register(dir) ⇒ Object
Search ‘dir` and load all Ruby files under it.
-
.run(config) ⇒ Object
Check each instance against ‘config`.
Instance Method Summary collapse
-
#abort(message, *extras) ⇒ Object
A fancier ‘abort` and `warn`.
-
#initialize(config) ⇒ Check
constructor
A new instance of Check.
-
#ok? ⇒ Boolean
Is everything good to go? Implemented by subclasses.
-
#run ⇒ Object
Warn, fix, or abort.
- #warn(message, *extras) ⇒ Object
Constructor Details
#initialize(config) ⇒ Check
Returns a new instance of Check.
33 34 35 |
# File 'lib/boxen/check.rb', line 33 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
31 32 33 |
# File 'lib/boxen/check.rb', line 31 def config @config end |
Class Method Details
.checks(config) ⇒ Object
A collection of preflight instances for ‘config`. An instance is created for every constant under `self` that’s also a subclass of ‘self`.
13 14 15 16 17 |
# 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 |
.register(dir) ⇒ Object
Search ‘dir` and load all Ruby files under it.
21 22 23 |
# File 'lib/boxen/check.rb', line 21 def self.register(dir) Dir["#{dir}/*.rb"].sort.each { |f| load f } end |
.run(config) ⇒ Object
Check each instance against ‘config`.
27 28 29 |
# File 'lib/boxen/check.rb', line 27 def self.run(config) checks(config).each { |check| check.run unless check.ok? } end |
Instance Method Details
#abort(message, *extras) ⇒ Object
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.
53 54 55 56 57 |
# File 'lib/boxen/check.rb', line 53 def abort(, *extras) extras << { :color => :red } warn , *extras exit 1 end |
#ok? ⇒ Boolean
Is everything good to go? Implemented by subclasses.
39 40 41 |
# File 'lib/boxen/check.rb', line 39 def ok? raise "Subclasses must implement this method." end |
#run ⇒ Object
Warn, fix, or abort. Implemented by subclasses.
45 46 47 |
# File 'lib/boxen/check.rb', line 45 def run raise "Subclasses must implement this method." end |
#warn(message, *extras) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/boxen/check.rb', line 59 def warn(, *extras) = Hash === extras.last ? extras.pop : {} color = [:color] || :yellow $stderr.puts ANSI.send(color) { "--> #{}" } unless extras.empty? extras.each { |line| $stderr.puts " #{line}" } end $stderr.puts end |