Class: Trifle::Logger::Tracer::Hash
- Inherits:
-
Object
- Object
- Trifle::Logger::Tracer::Hash
- Defined in:
- lib/trifle/logger/tracer/hash.rb
Instance Attribute Summary collapse
-
#artifacts ⇒ Object
Returns the value of attribute artifacts.
-
#data ⇒ Object
Returns the value of attribute data.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#key ⇒ Object
Returns the value of attribute key.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #artifact(name, path) ⇒ Object
- #bump ⇒ Object
- #config ⇒ Object
- #dump_message(message, type:, state:) ⇒ Object
- #dump_result(result) ⇒ Object
- #fail! ⇒ Object
- #ignore! ⇒ Object
-
#initialize(key:, reference: nil, meta: nil, config: nil) ⇒ Hash
constructor
A new instance of Hash.
- #keys ⇒ Object
- #liftoff ⇒ Object
- #now ⇒ Object
- #pop_all_artifacts ⇒ Object
- #pop_all_data ⇒ Object
- #running? ⇒ Boolean
- #set_defaults! ⇒ Object
- #success! ⇒ Object
- #success? ⇒ Boolean
- #tag(tag) ⇒ Object
-
#trace(message, state: :success, head: false) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #warn! ⇒ Object
- #wrapup ⇒ Object
Constructor Details
#initialize(key:, reference: nil, meta: nil, config: nil) ⇒ Hash
Returns a new instance of Hash.
9 10 11 12 13 14 15 16 17 |
# File 'lib/trifle/logger/tracer/hash.rb', line 9 def initialize(key:, reference: nil, meta: nil, config: nil) @key = key @meta = @config = config set_defaults! trace("Tracer has been initialized for #{key}") @reference = reference || liftoff.first end |
Instance Attribute Details
#artifacts ⇒ Object
Returns the value of attribute artifacts.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def artifacts @artifacts end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def data @data end |
#ignore ⇒ Object
Returns the value of attribute ignore.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def ignore @ignore end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def key @key end |
#meta ⇒ Object
Returns the value of attribute meta.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def @meta end |
#reference ⇒ Object
Returns the value of attribute reference.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def reference @reference end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def state @state end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/trifle/logger/tracer/hash.rb', line 7 def @tags end |
Instance Method Details
#artifact(name, path) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/trifle/logger/tracer/hash.rb', line 81 def artifact(name, path) @data << { at: now, message: name, state: :success, type: :media, size: File.size(path) } @artifacts << path bump path end |
#bump ⇒ Object
117 118 119 120 121 122 |
# File 'lib/trifle/logger/tracer/hash.rb', line 117 def bump return unless @bumped_at && @bumped_at <= now - config.bump_every @bumped_at = now config.on_bump(self) end |
#config ⇒ Object
36 37 38 |
# File 'lib/trifle/logger/tracer/hash.rb', line 36 def config @config || Trifle::Logger.default end |
#dump_message(message, type:, state:) ⇒ Object
60 61 62 |
# File 'lib/trifle/logger/tracer/hash.rb', line 60 def (, type:, state:) @data << { at: now, message: , state: state, type: type } end |
#dump_result(result) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/trifle/logger/tracer/hash.rb', line 64 def dump_result(result) @data << { at: now, message: "#{@result_prefix}#{result.inspect}", state: :success, type: :raw } end |
#fail! ⇒ Object
88 89 90 |
# File 'lib/trifle/logger/tracer/hash.rb', line 88 def fail! @state = :error end |
#ignore! ⇒ Object
108 109 110 |
# File 'lib/trifle/logger/tracer/hash.rb', line 108 def ignore! @ignore = true end |
#keys ⇒ Object
40 41 42 43 |
# File 'lib/trifle/logger/tracer/hash.rb', line 40 def keys parts = key.split('/') parts.count.times.map { |i| parts[0..i].join('/') } end |
#liftoff ⇒ Object
112 113 114 115 |
# File 'lib/trifle/logger/tracer/hash.rb', line 112 def liftoff @bumped_at = now config.on_liftoff(self) end |
#now ⇒ Object
71 72 73 |
# File 'lib/trifle/logger/tracer/hash.rb', line 71 def now Time.now.to_i end |
#pop_all_artifacts ⇒ Object
32 33 34 |
# File 'lib/trifle/logger/tracer/hash.rb', line 32 def pop_all_artifacts @artifacts.pop(@artifacts.count) end |
#pop_all_data ⇒ Object
28 29 30 |
# File 'lib/trifle/logger/tracer/hash.rb', line 28 def pop_all_data @data.pop(@data.count) end |
#running? ⇒ Boolean
104 105 106 |
# File 'lib/trifle/logger/tracer/hash.rb', line 104 def running? @state == :running end |
#set_defaults! ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/trifle/logger/tracer/hash.rb', line 19 def set_defaults! @tags = [] @data = [] @artifacts = [] @state = :running @ignore = false @result_prefix = '=> ' end |
#success! ⇒ Object
96 97 98 |
# File 'lib/trifle/logger/tracer/hash.rb', line 96 def success! @state = :success end |
#success? ⇒ Boolean
100 101 102 |
# File 'lib/trifle/logger/tracer/hash.rb', line 100 def success? @state == :success end |
#tag(tag) ⇒ Object
75 76 77 78 79 |
# File 'lib/trifle/logger/tracer/hash.rb', line 75 def tag(tag) @tags << tag bump tag end |
#trace(message, state: :success, head: false) ⇒ Object
rubocop:disable Metrics/MethodLength
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trifle/logger/tracer/hash.rb', line 45 def trace(, state: :success, head: false) # rubocop:disable Metrics/MethodLength result = yield if block_given? rescue StandardError => e raise e ensure ( , type: head ? :head : :text, state: e ? :error : state ) dump_result(result) if block_given? bump result end |
#warn! ⇒ Object
92 93 94 |
# File 'lib/trifle/logger/tracer/hash.rb', line 92 def warn! @state = :warning end |
#wrapup ⇒ Object
124 125 126 127 |
# File 'lib/trifle/logger/tracer/hash.rb', line 124 def wrapup success! if running? config.on_wrapup(self) end |