Module: Arborist::CLI::Watch
- Extended by:
- Subcommand
- Defined in:
- lib/arborist/command/watch.rb
Overview
Command to watch events in an Arborist manager.
Constant Summary collapse
- HEARTBEAT_CHARACTERS =
%w[💓 💗]
Class Method Summary collapse
-
.diff_pairs(data) ⇒ Object
Return a string showing the differences in a delta event’s change
data. -
.dump_event(event) ⇒ Object
Return a String representation of the specified
event. -
.subscribe_to_node_events(client) ⇒ Object
Establish a subscription to all node events via the specified
client.
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
.diff_pairs(data) ⇒ Object
Return a string showing the differences in a delta event’s change data.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/arborist/command/watch.rb', line 119 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 |
.dump_event(event) ⇒ Object
Return a String representation of the specified event.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/arborist/command/watch.rb', line 96 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 |
.subscribe_to_node_events(client) ⇒ Object
Establish a subscription to all node events via the specified client.
86 87 88 89 90 91 92 |
# File 'lib/arborist/command/watch.rb', line 86 def subscribe_to_node_events( client ) subid = client.subscribe( identifier: '_' ) sock = client.event_api sock.subscribe( subid ) return subid end |