diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-23 19:51:56 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-23 19:51:56 +0000 |
commit | 09227fd37c5de73810f1fb3219766469941580fa (patch) | |
tree | a26a3d84149ac88162f92e1a87c66a820ce540fb | |
parent | DBIish wants strings (diff) | |
download | Ultramarine-09227fd37c5de73810f1fb3219766469941580fa.tar.gz Ultramarine-09227fd37c5de73810f1fb3219766469941580fa.tar.bz2 Ultramarine-09227fd37c5de73810f1fb3219766469941580fa.zip |
Collection class
-rw-r--r-- | lib/Ultramarine/Model/Collection.pm6 | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Ultramarine/Model/Collection.pm6 b/lib/Ultramarine/Model/Collection.pm6 new file mode 100644 index 0000000..c8cddf7 --- /dev/null +++ b/lib/Ultramarine/Model/Collection.pm6 @@ -0,0 +1,34 @@ +use v6.d.PREVIEW; +need Ultramarine::Model::DirScanner; + +class Ultramarine::Model::Collection { + has $.db is required handles <all-songs>; + has $.dirscan is required; + has $.file-class is required; + + method new(|c) { + my $self = self.bless(|c); + start $self.update(); + return $self; + } + + has Promise $.is-ready .= new; + has $!mark-ready = $!is-ready.vow; + + method update() { + react whenever $.dirscan.scan -> $path { + when $path ~~ Ultramarine::Model::DirScanner::EndOfScan { + # we should use this to check that all the files in + # the db have been seen, and delete those that haven't + $!mark-ready.keep(True); + } + when $path ~~ IO::Path & :f { + my $mtime = $path.modified.floor; + unless $.db.is-up-to-date(:$path,:$mtime) { + my %metadata = $.file-class.new(:$path).metadata; + $.db.set-song(:$path,:$mtime,:%metadata) if %metadata.keys; + } + } + } + } +} |