module Arborist::CLI::RunOnce
Command to run a monitor in single-run mode
Public Instance Methods
display_results( results )
click to toggle source
Display the results of running a monitor.
# File lib/arborist/command/run_once.rb, line 101 def display_results( results ) width = TTY::Screen.width results.keys.sort.each do |identifier| result = results[ identifier ] prompt.say( highlight_string(identifier) ) prompt.say( PP.pp(result, '', width) ) prompt.say "\n" end end
fileize( mod_name )
click to toggle source
Return the specified mod_name
as the corresponding file name.
# File lib/arborist/command/run_once.rb, line 94 def fileize( mod_name ) return mod_name.sub( /.*::/, '' ). gsub( /([a-z0-9])([A-Z])/, '\\1_\\2' ).downcase end
monitors_from_args( args, options )
click to toggle source
Figure out what kind of monitor is being run from the provided args
and options
and return instances of them.
# File lib/arborist/command/run_once.rb, line 64 def monitors_from_args( args, options ) return args.flat_map do |monitor| if File.exist?( monitor ) Arborist::Monitor.load( monitor ) else wrap_monitor_callback( monitor, options ) end end end
wrap_monitor_callback( mod_name, options )
click to toggle source
Try to load the monitor callback with the specified mod_name
and return it inside a plain monitor object.
# File lib/arborist/command/run_once.rb, line 77 def wrap_monitor_callback( mod_name, options ) filename = fileize( mod_name ) required_file = options[ :require ] || "arborist/monitor/%s" % [ filename ] self.log.debug "Loading monitor callback from %p" % [ required_file ] require( required_file ) exec_module = Arborist::Monitor.const_get( mod_name ) monitor = Arborist::Monitor.new( exec_module.name, filename ) monitor.exec( exec_module ) monitor.match( type: options[:type] ) return [ monitor ] end