Class: RailsPerformance::DataSource
- Inherits:
-
Object
- Object
- RailsPerformance::DataSource
- Defined in:
- lib/rails_performance/data_source.rb
Instance Attribute Summary collapse
-
#q ⇒ Object
readonly
Returns the value of attribute q.
Class Method Summary collapse
Instance Method Summary collapse
- #db(storage = RP::Collection.new) ⇒ Object (also: #add_to)
-
#initialize(q: {}) ⇒ DataSource
constructor
A new instance of DataSource.
- #store ⇒ Object
Constructor Details
#initialize(q: {}) ⇒ DataSource
5 6 7 8 |
# File 'lib/rails_performance/data_source.rb', line 5 def initialize(q: {}) q[:on] ||= Date.today @q = q end |
Instance Attribute Details
#q ⇒ Object (readonly)
Returns the value of attribute q.
3 4 5 |
# File 'lib/rails_performance/data_source.rb', line 3 def q @q end |
Class Method Details
.all ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/rails_performance/data_source.rb', line 10 def DataSource.all result = RP::Collection.new RP::Utils.days.times do |e| RP::DataSource.new(q: { on: e.days.ago.to_date }).add_to(result) end result end |
Instance Method Details
#db(storage = RP::Collection.new) ⇒ Object Also known as: add_to
18 19 20 21 22 23 |
# File 'lib/rails_performance/data_source.rb', line 18 def db(storage = RP::Collection.new) store do |record| storage.add(record) end storage end |
#store ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_performance/data_source.rb', line 26 def store #puts "\n\n [REDIS] --> #{query}\n\n" keys = RP.redis.keys(query) return [] if keys.blank? values = RP.redis.mget(keys) keys.each_with_index do |key, index| yield RP::Record.new(key, values[index]) end end |