Class: Thing
- Inherits:
-
Teron
- Object
- Teron
- Thing
- Includes:
- ActionView::Helpers::DateHelper, ActionView::Helpers::NumberHelper, GreenHat::FileTypes, GreenHat::Formatters, GreenHat::Kind, GreenHat::Spinner, GreenHat::ThingHelpers
- Defined in:
- lib/greenhat/thing.rb
Overview
Top Level what everything is
Instance Method Summary collapse
-
#archive?(archive_names) ⇒ Boolean
Filter / Archive Pattern Matching.
-
#blank? ⇒ Boolean
Helper for empty logs.
-
#data ⇒ Object
Processor.
- #field_processing ⇒ Object
-
#fields ⇒ Object
Processor.
-
#formatter ⇒ Object
Helper Formatter Method.
- #friendly_name ⇒ Object
-
#log? ⇒ Boolean
Log Identifier Helper.
- #output(print_it = true) ⇒ Object
- #process ⇒ Object
-
#processed? ⇒ Boolean
Hashed values searching.
- #raw ⇒ Object
- #raw_read ⇒ Object
- #setup ⇒ Object
Methods included from GreenHat::FileTypes
Methods included from GreenHat::Kind
#check_oj_parse?, #kind_collect, #kind_pattern_match, #kind_setup, #prompt, #prompt_for_kind
Methods included from GreenHat::Spinner
#humanize, #spin_done, #spin_start, #time
Methods included from GreenHat::ThingHelpers
#build_path, #inspect, #type_check
Methods included from GreenHat::Formatters
#dmesg_split, #flatten_hash, #format_api_json, #format_bracket_log, #format_clean_raw, #format_colon_split_strip, #format_dotenv, #format_free_m, #format_gitlab_status, #format_gitlab_tail, #format_json, #format_json_shell, #format_json_time, #format_json_traverse, #format_multiline_json, #format_nginx, #format_raw, #format_shellwords, #format_syslog, #format_syslog_row, #format_table, #format_time_json, #format_time_parse, #format_time_shellwords, #format_time_space, #json_shellwords_fallback, #log_format, #log_type, #mia
Instance Method Details
#archive?(archive_names) ⇒ Boolean
Filter / Archive Pattern Matching
67 68 69 |
# File 'lib/greenhat/thing.rb', line 67 def archive?(archive_names) archive_names.map(&:to_s).any? { |x| archive.name.include? x } end |
#blank? ⇒ Boolean
Helper for empty logs
72 73 74 |
# File 'lib/greenhat/thing.rb', line 72 def blank? data.blank? end |
#data ⇒ Object
Processor
47 48 49 50 51 |
# File 'lib/greenhat/thing.rb', line 47 def data process unless parsed result end |
#field_processing ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/greenhat/thing.rb', line 132 def field_processing if data.instance_of?(Array) data.select { |x| x.instance_of?(Hash) }.map(&:keys).flatten.uniq else [] end rescue StandardError => e LogBot.fatal('Process', message: e., backtrace: e.backtrace.first) [] end |
#fields ⇒ Object
Processor
54 55 56 57 58 |
# File 'lib/greenhat/thing.rb', line 54 def fields process unless parsed result_fields end |
#formatter ⇒ Object
Helper Formatter Method
105 106 107 |
# File 'lib/greenhat/thing.rb', line 105 def formatter "format_#{kind}".to_sym end |
#friendly_name ⇒ Object
31 32 33 |
# File 'lib/greenhat/thing.rb', line 31 def friendly_name "#{archive.friendly_name.pastel(:blue)} #{name.pastel(:green)}" end |
#log? ⇒ Boolean
Log Identifier Helper
95 96 97 |
# File 'lib/greenhat/thing.rb', line 95 def log? GreenHat::SuperLog.log? kind end |
#output(print_it = true) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/greenhat/thing.rb', line 86 def output(print_it = true) if print_it puts raw.join("\n") else raw end end |
#process ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/greenhat/thing.rb', line 109 def process # Read First if Needed (Spinner) raw_read if raw_result.nil? if methods.include? formatter spin_start("Parse #{name.pastel(:blue)} #{kind.to_s.pastel(:bright_black)} ") begin send(formatter) rescue StandardError => e LogBot.fatal('Process', message: e., backtrace: e.backtrace.first) end spin_done else LogBot.fatal('Thing', "No Formatter for #{formatter}") end self.parsed = true self.result_fields = field_processing save! end |
#processed? ⇒ Boolean
Hashed values searching
100 101 102 |
# File 'lib/greenhat/thing.rb', line 100 def processed? kind != :raw end |
#raw ⇒ Object
60 61 62 63 64 |
# File 'lib/greenhat/thing.rb', line 60 def raw raw_read if raw_result.nil? raw_result end |
#raw_read ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/greenhat/thing.rb', line 76 def raw_read spin_start("Read #{name.pastel(:blue)} #{size.pastel(:bright_black)}") self.raw_result = File.read(file).split("\n") rescue StandardError => e LogBot.fatal('Raw Read', message: e., backtrace: e.backtrace.first) self.raw_result = '' ensure spin_done end |
#setup ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/greenhat/thing.rb', line 35 def setup self.name = build_path('/') self.path = build_path.gsub(/[^\w\s]/, '_') self.size = number_to_human_size File.size(file) kind_collect # Set Kind and Type kind_setup save! end |