Class: RailsPerformance::DataSource
- Inherits:
-
Object
- Object
- RailsPerformance::DataSource
- Defined in:
- lib/rails_performance/data_source.rb
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 = RP::Models::Collection.new) ⇒ Object
- #db ⇒ Object
- #default? ⇒ Boolean
-
#initialize(q: {}, type:, klass:) ⇒ DataSource
constructor
A new instance of DataSource.
- #store ⇒ Object
Constructor Details
#initialize(q: {}, type:, klass:) ⇒ DataSource
Returns a new instance of DataSource.
5 6 7 8 9 10 11 12 |
# File 'lib/rails_performance/data_source.rb', line 5 def initialize(q: {}, type:, klass:) @klass = klass @type = type q[:on] ||= Date.today @q = q #puts " [DataSource Q] --> #{@q.inspect}\n\n" end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/rails_performance/data_source.rb', line 3 def klass @klass end |
#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 |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/rails_performance/data_source.rb', line 3 def type @type end |
Instance Method Details
#add_to(storage = RP::Models::Collection.new) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rails_performance/data_source.rb', line 26 def add_to(storage = RP::Models::Collection.new) store do |record| storage.add(record) end storage end |
#db ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rails_performance/data_source.rb', line 14 def db result = RP::Models::Collection.new (RP::Utils.days + 1).times do |e| RP::DataSource.new(q: self.q.merge({ on: e.days.ago.to_date }), klass: klass, type: type).add_to(result) end result end |
#default? ⇒ Boolean
22 23 24 |
# File 'lib/rails_performance/data_source.rb', line 22 def default? @q.keys == [:on] end |
#store ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_performance/data_source.rb', line 33 def store keys, values = Utils.fetch_from_redis(query) return [] if keys.blank? keys.each_with_index do |key, index| yield klass.new(key, values[index]) end end |