From 09227fd37c5de73810f1fb3219766469941580fa Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 23 Dec 2017 19:51:56 +0000 Subject: Collection class --- lib/Ultramarine/Model/Collection.pm6 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/Ultramarine/Model/Collection.pm6 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 ; + 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; + } + } + } + } +} -- cgit v1.2.3