Class: RailsPerformance::DataSource
- Inherits:
-
Object
- Object
- RailsPerformance::DataSource
- Defined in:
- lib/rails_performance/data_source.rb
Constant Summary collapse
- KLASSES =
{ requests: RailsPerformance::Models::RequestRecord, sidekiq: RailsPerformance::Models::SidekiqRecord, delayed_job: RailsPerformance::Models::DelayedJobRecord, grape: RailsPerformance::Models::GrapeRecord, rake: RailsPerformance::Models::RakeRecord, custom: RailsPerformance::Models::CustomRecord, resources: RailsPerformance::Models::ResourceRecord }
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add_to(storage = RailsPerformance::Models::Collection.new) ⇒ Object
- #db ⇒ Object
- #default? ⇒ Boolean
-
#initialize(type:, q: {}, days: RailsPerformance::Utils.days(RailsPerformance.duration)) ⇒ DataSource
constructor
A new instance of DataSource.
- #store ⇒ Object
Constructor Details
#initialize(type:, q: {}, days: RailsPerformance::Utils.days(RailsPerformance.duration)) ⇒ DataSource
Returns a new instance of DataSource.
15 16 17 18 19 20 21 |
# File 'lib/rails_performance/data_source.rb', line 15 def initialize(type:, q: {}, days: RailsPerformance::Utils.days(RailsPerformance.duration)) @type = type @klass = KLASSES[type] q[:on] ||= Date.today @q = q @days = days end |
Instance Attribute Details
#days ⇒ Object (readonly)
Returns the value of attribute days.
13 14 15 |
# File 'lib/rails_performance/data_source.rb', line 13 def days @days end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
13 14 15 |
# File 'lib/rails_performance/data_source.rb', line 13 def klass @klass end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
13 14 15 |
# File 'lib/rails_performance/data_source.rb', line 13 def q @q end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/rails_performance/data_source.rb', line 13 def type @type end |
Instance Method Details
#add_to(storage = RailsPerformance::Models::Collection.new) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rails_performance/data_source.rb', line 36 def add_to(storage = RailsPerformance::Models::Collection.new) store do |record| storage.add(record) end storage end |
#db ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/rails_performance/data_source.rb', line 23 def db result = RailsPerformance::Models::Collection.new now = RailsPerformance::Utils.kind_of_now (0..days).to_a.reverse_each do |e| RailsPerformance::DataSource.new(q: q.merge({on: (now - e.days).to_date}), type: type).add_to(result) end result end |
#default? ⇒ Boolean
32 33 34 |
# File 'lib/rails_performance/data_source.rb', line 32 def default? @q.keys == [:on] end |
#store ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/rails_performance/data_source.rb', line 43 def store keys, values = Utils.fetch_from_redis(query) return [] if keys.blank? keys.each_with_index do |key, index| yield klass.from_db(key, values[index]) end end |