Class: WavefrontDisplay::Write

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-cli/display/write.rb

Overview

Format human-readable output when writing points. In this context data is a Hash of the form { sent: 1, rejected: 0, unsent: 0 }

Direct Known Subclasses

Distribution

Constant Summary

Constants included from WavefrontCli::Constants

WavefrontCli::Constants::ALL_PAGE_SIZE, WavefrontCli::Constants::DEFAULT_CONFIG, WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::EVENT_STATE_DIR, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS, WavefrontCli::Constants::SEARCH_SPLIT

Instance Attribute Summary collapse

Attributes inherited from Base

#data, #options, #raw

Instance Method Summary collapse

Methods inherited from Base

#_prioritize_keys, #display_brief_freetext_results, #do_delete, #do_import, #do_list, #do_list_brief, #do_list_fields, #do_queries, #do_search, #do_search_brief, #do_search_fields, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #filter_data, #filter_fields_as_arr, #freetext_keys, #friendly_name, #human_time, #index_of_final_item, #initialize, #key_width, #long_output, #multicolumn, #pagination_line, #prioritize_keys, #priority_keys, #quoted, #readable_time, #readable_time_arr, #run, #run_error, #run_list, #run_search, #search_display_keys, #search_identifier_key, #time_formats

Constructor Details

This class inherits a constructor from WavefrontDisplay::Base

Instance Attribute Details

#not_sentObject (readonly)

Returns the value of attribute not_sent.



11
12
13
# File 'lib/wavefront-cli/display/write.rb', line 11

def not_sent
  @not_sent
end

Instance Method Details

#do_fileObject



24
25
26
# File 'lib/wavefront-cli/display/write.rb', line 24

def do_file
  do_point
end

#do_pointObject



13
14
15
16
17
18
# File 'lib/wavefront-cli/display/write.rb', line 13

def do_point
  @not_sent = data['rejected'] + data['unsent']
  report unless nothing_to_say?

  raise unless not_sent.zero?
end

#nothing_to_say?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/wavefront-cli/display/write.rb', line 20

def nothing_to_say?
  options[:quiet] || not_sent.positive?
end

#reportObject



28
29
30
31
32
33
34
# File 'lib/wavefront-cli/display/write.rb', line 28

def report
  %w[sent rejected unsent].each do |status|
    puts format('  %12<status>s %<count>d',
                status: status,
                count: data[status])
  end
end