Class: Ektoplayer::Models::Database
- Defined in:
- lib/ektoplayer/models/database.rb
Overview
This model represents the state of the database. Events:
- changed
-
the database has been modified
- update_started
-
database update has been started
- update_finished
-
database update has been finished
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #album_count ⇒ Object
- #get_description(*a) ⇒ Object
-
#initialize(client) ⇒ Database
constructor
A new instance of Database.
- #stop! ⇒ Object
- #track_count ⇒ Object
- #update(**opts) ⇒ Object
- #updating? ⇒ Boolean
Constructor Details
#initialize(client) ⇒ Database
Returns a new instance of Database.
15 16 17 18 19 20 |
# File 'lib/ektoplayer/models/database.rb', line 15 def initialize(client) super() @client = client @client.database.events.on(:changed) { @events.trigger(:changed) } @events.register(:update_started, :changed, :update_finished) end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
13 14 15 |
# File 'lib/ektoplayer/models/database.rb', line 13 def events @events end |
Instance Method Details
#album_count ⇒ Object
23 |
# File 'lib/ektoplayer/models/database.rb', line 23 def album_count; @client.database.album_count end |
#get_description(*a) ⇒ Object
25 26 27 |
# File 'lib/ektoplayer/models/database.rb', line 25 def get_description(*a) @client.database.get_description(*a) end |
#stop! ⇒ Object
33 34 35 36 |
# File 'lib/ektoplayer/models/database.rb', line 33 def stop! @update_thread and @update_thread.kill @update_thread = nil end |
#track_count ⇒ Object
22 |
# File 'lib/ektoplayer/models/database.rb', line 22 def track_count; @client.database.track_count end |
#update(**opts) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ektoplayer/models/database.rb', line 38 def update(**opts) unless updating? db_updater = DatabaseUpdater.new(@client.database) @update_thread = Thread.new do @events.trigger(:update_started) db_updater.update(**opts) @events.trigger(:update_finished) end else Application.log(self, 'already updating') end end |
#updating? ⇒ Boolean
29 30 31 |
# File 'lib/ektoplayer/models/database.rb', line 29 def updating? @update_thread and @update_thread.alive? end |