Arborist::CLI::

RunOnce

module
Extended With
Arborist::CLI::Subcommand

Command to run a monitor in single-run mode

Public Instance Methods

anchor
display_results( results )

Display the results of running a monitor.

# File lib/arborist/command/run_once.rb, line 100
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
anchor
fileize( mod_name )

Return the specified mod_name as the corresponding file name.

# File lib/arborist/command/run_once.rb, line 93
def fileize( mod_name )
        return mod_name.sub( /.*::/, '' ).
                gsub( /([a-z0-9])([A-Z])/, '\1_\2' ).downcase
end
anchor
monitors_from_args( args, options )

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 63
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
anchor
wrap_monitor_callback( mod_name, options )

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 76
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