Class: Solarium::Database
- Inherits:
-
Object
- Object
- Solarium::Database
- Defined in:
- lib/solarium/database.rb
Overview
Public: Implements logic for interacting with the Solarium database.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Public: Either an exception that was thrown during database connection or nil.
Instance Method Summary collapse
-
#initialize(url) ⇒ Database
constructor
Public: Initializes a new instance of the Solarium::Database class.
-
#insert(collector) ⇒ Object
Public: Stores the information provided by a Solarium::Collector in the database.
-
#select_days(days) ⇒ Object
Public: Reads the specified number of days worth of data from the database.
Constructor Details
#initialize(url) ⇒ Database
Public: Initializes a new instance of the Solarium::Database class.
url - The URL for connecting to the SQL database.
14 15 16 17 18 |
# File 'lib/solarium/database.rb', line 14 def initialize url connect url rescue ::Exception => error @error = error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Public: Either an exception that was thrown during database connection or nil.
9 10 11 |
# File 'lib/solarium/database.rb', line 9 def error @error end |
Instance Method Details
#insert(collector) ⇒ Object
Public: Stores the information provided by a Solarium::Collector in the database.
collector - An instance of the Solarium::Collector class containing information to store.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/solarium/database.rb', line 23 def insert collector row = { time: DateTime.now, now: collector.now, today: collector.today, week: collector.week, lifetime: collector.lifetime } @connection[:solarium].insert row end |
#select_days(days) ⇒ Object
Public: Reads the specified number of days worth of data from the database.
days - The number of days worth of data to read.
37 38 39 40 41 42 |
# File 'lib/solarium/database.rb', line 37 def select_days days data = @connection[:solarium].where do time > DateTime.now - days end return data.to_a end |