Class: RailsPerformance::DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/data_source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#qObject (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

.allObject



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

#storeObject



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