Class: EventMeter::Event
- Inherits:
-
Object
- Object
- EventMeter::Event
- Defined in:
- lib/event_meter/event.rb
Constant Summary collapse
- INVALID_EVENT_NAME =
"event_meter.invalid"
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
- #failure(error_or_attributes = nil, attributes = {}) ⇒ Object
-
#initialize(name, attributes = nil, keyword_attributes = {}, started_at: nil, error: nil) ⇒ Event
constructor
A new instance of Event.
- #skip(reason_or_attributes = nil, attributes = {}) ⇒ Object
- #success(attributes = {}) ⇒ Object
Constructor Details
#initialize(name, attributes = nil, keyword_attributes = {}, started_at: nil, error: nil) ⇒ Event
Returns a new instance of Event.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/event_meter/event.rb', line 22 def initialize(name, attributes = nil, keyword_attributes = {}, started_at: nil, error: nil) @started_at = nil @finished_at = nil @status = nil @recorded = false @error = nil if error @name = INVALID_EVENT_NAME @base_attributes = {} @error = error return end @started_at = started_at&.utc @name = normalize_name(name) @base_attributes = normalize_start_attributes(attributes, keyword_attributes) rescue StandardError => error @name = fallback_name(name) @base_attributes = {} @error = error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
12 13 14 |
# File 'lib/event_meter/event.rb', line 12 def error @error end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
12 13 14 |
# File 'lib/event_meter/event.rb', line 12 def finished_at @finished_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/event_meter/event.rb', line 12 def name @name end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
12 13 14 |
# File 'lib/event_meter/event.rb', line 12 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/event_meter/event.rb', line 12 def status @status end |
Class Method Details
.failed(error) ⇒ Object
18 19 20 |
# File 'lib/event_meter/event.rb', line 18 def self.failed(error) new(INVALID_EVENT_NAME, error: error) end |
.start(name, attributes, keyword_attributes, started_at:) ⇒ Object
14 15 16 |
# File 'lib/event_meter/event.rb', line 14 def self.start(name, attributes, keyword_attributes, started_at:) new(name, attributes, keyword_attributes, started_at: started_at) end |
Instance Method Details
#error? ⇒ Boolean
61 62 63 |
# File 'lib/event_meter/event.rb', line 61 def error? !error.nil? end |
#failure(error_or_attributes = nil, attributes = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/event_meter/event.rb', line 55 def failure(error_or_attributes = nil, attributes = {}) finish("failure") do normalize_error_attributes(error_or_attributes, attributes) end end |
#skip(reason_or_attributes = nil, attributes = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/event_meter/event.rb', line 49 def skip(reason_or_attributes = nil, attributes = {}) finish("skipped") do normalize_reason_attributes(reason_or_attributes, attributes, :skip_reason) end end |
#success(attributes = {}) ⇒ Object
45 46 47 |
# File 'lib/event_meter/event.rb', line 45 def success(attributes = {}) finish("success") { attributes } end |