Class: Railswatch::DataSource
- Inherits:
-
Object
- Object
- Railswatch::DataSource
- Defined in:
- lib/railswatch/data_source.rb
Defined Under Namespace
Classes: RelationWrapper
Constant Summary collapse
- KLASSES =
{ requests: Railswatch::Models::RequestRecord, sidekiq: Railswatch::Models::SidekiqRecord, delayed_job: Railswatch::Models::DelayedJobRecord, grape: Railswatch::Models::GrapeRecord, rake: Railswatch::Models::RakeRecord, custom: Railswatch::Models::CustomRecord, resources: Railswatch::Models::ResourceRecord }.freeze
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #db ⇒ Object
- #default? ⇒ Boolean
-
#initialize(type:, query: {}, days: Railswatch::Utils.days(Railswatch.duration)) ⇒ DataSource
constructor
A new instance of DataSource.
Constructor Details
#initialize(type:, query: {}, days: Railswatch::Utils.days(Railswatch.duration)) ⇒ DataSource
Returns a new instance of DataSource.
36 37 38 39 40 41 |
# File 'lib/railswatch/data_source.rb', line 36 def initialize(type:, query: {}, days: Railswatch::Utils.days(Railswatch.duration)) @type = type @klass = KLASSES.fetch(type) @query = query @days = days end |
Instance Attribute Details
#days ⇒ Object (readonly)
Returns the value of attribute days.
34 35 36 |
# File 'lib/railswatch/data_source.rb', line 34 def days @days end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
34 35 36 |
# File 'lib/railswatch/data_source.rb', line 34 def klass @klass end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
34 35 36 |
# File 'lib/railswatch/data_source.rb', line 34 def query @query end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
34 35 36 |
# File 'lib/railswatch/data_source.rb', line 34 def type @type end |
Instance Method Details
#db ⇒ Object
43 44 45 46 47 |
# File 'lib/railswatch/data_source.rb', line 43 def db scope = klass.all scope = apply_time_window(scope) RelationWrapper.new(apply_filters(scope)) end |
#default? ⇒ Boolean
49 50 51 |
# File 'lib/railswatch/data_source.rb', line 49 def default? query.empty? end |