Class: Ektoplayer::Models::Database

Inherits:
Model
  • Object
show all
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

Instance Method Summary collapse

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

#eventsObject (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_countObject



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_countObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/ektoplayer/models/database.rb', line 29

def updating?
   @update_thread and @update_thread.alive?
end