Arborist::CLI::

Watch

module
Extended With
Arborist::CLI::Subcommand

Command to watch events in an Arborist manager.

Constants

HEARTBEAT_CHARACTERS

Public Instance Methods

anchor
diff_pairs( data )

Return a string showing the differences in a delta event's change data.

# File lib/arborist/command/watch.rb, line 118
def diff_pairs( data )
        diff = data.collect do |key, pairs|
                if pairs.is_a?( Hash )
                        diff_pairs( pairs )
                else
                        val1, val2 = *pairs
                        "%s: %s -> %s" % [
                                hl.dark.white( key ),
                                hl.yellow( val1 ),
                                hl.bold.yellow( val2 )
                        ]
                end
        end

        return hl.dark.white( diff.join(', ') )
end
anchor
dump_event( event )

Return a String representation of the specified event.

# File lib/arborist/command/watch.rb, line 95
def dump_event( event )
        event_type = event['type']
        id = event['identifier']

        case event_type
        when 'node.update'
                type, status, errors = event['data'].values_at( *%w'type status errors' )
                return "%s updated: %s is %s%s" % [
                        hl.cyan( id ),
                        type,
                        hl.decorate( status, status.to_sym ),
                        errors ? " (#{errors})" : ''
                ]
        when 'node.delta'
                pairs = diff_pairs( event['data'] )
                return "%s delta, changes: %s" % [ hl.cyan( id ), pairs ]
        else
                return "%s event: %p" % [ hl.dark.white( event_type ), event ]
        end
end
anchor
subscribe_to_node_events( client )

Establish a subscription to all node events via the specified client.

# File lib/arborist/command/watch.rb, line 85
def subscribe_to_node_events( client )
        subid = client.subscribe( identifier: '_' )
        sock = client.event_api

        sock.subscribe( subid )
        return subid
end