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, }
Instance Attribute Summary collapse
-
#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(q: {}, type:) ⇒ DataSource
constructor
A new instance of DataSource.
- #store ⇒ Object
Constructor Details
#initialize(q: {}, type:) ⇒ DataSource
Returns a new instance of DataSource.
14 15 16 17 18 19 |
# File 'lib/rails_performance/data_source.rb', line 14 def initialize(q: {}, type:) @type = type @klass = KLASSES[type] q[:on] ||= Date.today @q = q end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
12 13 14 |
# File 'lib/rails_performance/data_source.rb', line 12 def klass @klass end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
12 13 14 |
# File 'lib/rails_performance/data_source.rb', line 12 def q @q end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/rails_performance/data_source.rb', line 12 def type @type end |
Instance Method Details
#add_to(storage = RailsPerformance::Models::Collection.new) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rails_performance/data_source.rb', line 33 def add_to(storage = RailsPerformance::Models::Collection.new) store do |record| storage.add(record) end storage end |
#db ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rails_performance/data_source.rb', line 21 def db result = RailsPerformance::Models::Collection.new (0..(RailsPerformance::Utils.days + 1)).to_a.reverse.each do |e| RailsPerformance::DataSource.new(q: self.q.merge({ on: (Time.current - e.days).to_date }), type: type).add_to(result) end result end |
#default? ⇒ Boolean
29 30 31 |
# File 'lib/rails_performance/data_source.rb', line 29 def default? @q.keys == [:on] end |
#store ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/rails_performance/data_source.rb', line 40 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 |