Module: Arborist::CLI::RunOnce

Extended by:
Subcommand
Defined in:
lib/arborist/command/run_once.rb

Overview

Command to run a monitor in single-run mode

Class Method Summary collapse

Methods included from Subcommand

display_table, error_string, exit_now!, extended, headline_string, help_now!, highlight_string, hl, prompt, skips_around, skips_post, skips_pre, success_string, unless_dryrun, visible_chars

Class Method Details

.display_results(results) ⇒ Object

Display the results of running a monitor.



102
103
104
105
106
107
108
109
110
111
# File 'lib/arborist/command/run_once.rb', line 102

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) ⇒ Object

Return the specified mod_name as the corresponding file name.



95
96
97
98
# File 'lib/arborist/command/run_once.rb', line 95

def fileize( mod_name )
	return mod_name.sub( /.*::/, '' ).
		gsub( /([a-z0-9])([A-Z])/, '\\1_\\2' ).downcase
end

.monitors_from_args(args, options) ⇒ Object

Figure out what kind of monitor is being run from the provided args and options and return instances of them.



65
66
67
68
69
70
71
72
73
# File 'lib/arborist/command/run_once.rb', line 65

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) ⇒ Object

Try to load the monitor callback with the specified mod_name and return it inside a plain monitor object.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/arborist/command/run_once.rb', line 78

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