Class: Chronometer::Command::Chronometer
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- Chronometer::Command::Chronometer
- Defined in:
- lib/chronometer/command.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Chronometer
constructor
A new instance of Chronometer.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Chronometer
Returns a new instance of Chronometer.
25 26 27 28 29 30 31 |
# File 'lib/chronometer/command.rb', line 25 def initialize(argv) @chronofile = argv.shift_argument @output = argv.option('output', "#{@chronofile}.trace") @file_to_load = argv.shift_argument @arguments = argv.remainder! if @chronofile && @file_to_load super end |
Class Method Details
.options ⇒ Object
19 20 21 22 23 |
# File 'lib/chronometer/command.rb', line 19 def self. [ ['--output=TRACE', 'The path to the tracefile chronometer will write'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/chronometer/command.rb', line 51 def run argv = ::ARGV.dup ::ARGV.replace(@arguments) time { load(@file_to_load) } ensure ::ARGV.replace(argv) end |
#validate! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chronometer/command.rb', line 33 def validate! super help! 'Must supply a chronofile' unless @chronofile @chronofile_contents = begin File.read(@chronofile) rescue StandardError help!("No such chronofile `#{@chronofile}`") end help! 'Must supply a ruby file to load' unless @file_to_load @file_to_load = ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).push('.').reduce(nil) do |a, e| next a if a a = File.join(e, @file_to_load) next nil unless File.file?(a) a end help! "Could not find `#{@file_to_load}`" unless @file_to_load end |