Class: RailsPerformance::Events::Record
- Inherits:
-
Object
- Object
- RailsPerformance::Events::Record
- Defined in:
- lib/rails_performance/events/record.rb
Constant Summary collapse
- DEFAULT_COLOR =
"#FF00FF"
- DEFAULT_LABEL_COLOR =
"#FF00FF"
- DEFAULT_LABEL_ORIENTATION =
"horizontal"
Instance Attribute Summary collapse
-
#datetimei ⇒ Object
readonly
Returns the value of attribute datetimei.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, datetimei:, options: {}) ⇒ Record
constructor
A new instance of Record.
- #rails_performance_key ⇒ Object
- #save ⇒ Object
- #to_annotation ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(name:, datetimei:, options: {}) ⇒ Record
Returns a new instance of Record.
26 27 28 29 30 |
# File 'lib/rails_performance/events/record.rb', line 26 def initialize(name:, datetimei:, options: {}) @name = name @datetimei = datetimei @options = end |
Instance Attribute Details
#datetimei ⇒ Object (readonly)
Returns the value of attribute datetimei.
4 5 6 |
# File 'lib/rails_performance/events/record.rb', line 4 def datetimei @datetimei end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/rails_performance/events/record.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/rails_performance/events/record.rb', line 4 def @options end |
Class Method Details
.all ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rails_performance/events/record.rb', line 17 def all _, values = RailsPerformance::Utils.fetch_from_redis("rails_performance:records:events:*") Array(values).map do |value| json = JSON.parse(value) new(name: json["name"], datetimei: json["datetimei"], options: Hash(json["options"])) end end |
.create(name:, datetimei: Time.now.to_i, options: {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/rails_performance/events/record.rb', line 11 def create(name:, datetimei: Time.now.to_i, options: {}) instance = new(name: name, datetimei: datetimei, options: ) instance.save instance end |
Instance Method Details
#rails_performance_key ⇒ Object
36 37 38 |
# File 'lib/rails_performance/events/record.rb', line 36 def rails_performance_key "rails_performance:records:events:#{datetimei}|#{RailsPerformance::EVENTS_SCHEMA}" end |
#save ⇒ Object
32 33 34 |
# File 'lib/rails_performance/events/record.rb', line 32 def save RailsPerformance::Utils.save_to_redis(rails_performance_key, value) end |
#to_annotation ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_performance/events/record.rb', line 49 def to_annotation { x: datetimei * 1000, borderColor: .dig("borderColor") || DEFAULT_COLOR, label: { borderColor: .dig("label", "borderColor") || DEFAULT_LABEL_COLOR, orientation: .dig("label", "orientation") || DEFAULT_LABEL_ORIENTATION, text: .dig("label", "text") || name } } end |
#value ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rails_performance/events/record.rb', line 40 def value { name: name, datetime: RailsPerformance::Utils.from_datetimei(datetimei.to_i), datetimei: datetimei, options: } end |