Class: ProcessMetrics::Base
- Inherits:
-
Object
- Object
- ProcessMetrics::Base
- Defined in:
- lib/process_metrics/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(name, parent = nil) ⇒ Base
constructor
A new instance of Base.
- #measure(name, &block) ⇒ Object
- #save ⇒ Object
- #serialized_attributes ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, parent = nil) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 |
# File 'lib/process_metrics/base.rb', line 7 def initialize(name, parent=nil) @uuid = SecureRandom.uuid @parent_uuid = parent ? parent.uuid : nil @data = nil @name = name @started_at = Time.now @finished_at = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/process_metrics/base.rb', line 5 def data @data end |
#uuid ⇒ Object
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/process_metrics/base.rb', line 5 def uuid @uuid end |
Class Method Details
.work(name, parent = nil, &block) ⇒ Object
47 48 49 50 51 |
# File 'lib/process_metrics/base.rb', line 47 def self.work(name, parent=nil, &block) metric = ProcessMetrics::Base.new name, parent block.call metric metric.save end |
Instance Method Details
#attributes ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/process_metrics/base.rb', line 16 def attributes { uuid: @uuid, parent_uuid: @parent_uuid, name: @name, data: @data, started_at: @started_at, finished_at: @finished_at } end |
#measure(name, &block) ⇒ Object
43 44 45 |
# File 'lib/process_metrics/base.rb', line 43 def measure(name, &block) work(name, self, &block) end |
#save ⇒ Object
38 39 40 41 |
# File 'lib/process_metrics/base.rb', line 38 def save @finished_at = Time.now ProcessMetrics.config.persistence.save(self) end |
#serialized_attributes ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/process_metrics/base.rb', line 27 def serialized_attributes { uuid: @uuid, parent_uuid: @parent_uuid, name: @name, data: @data, started_at: @started_at.strftime("%Y-%m-%d %H:%M:%S.%N"), finished_at: @finished_at.strftime("%Y-%m-%d %H:%M:%S.%N") } end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/process_metrics/base.rb', line 53 def to_s self.class.name + " " + serialized_attributes.to_s end |