songbooks 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/songbooks.rb +1 -0
- data/lib/songbooks/folder.rb +41 -2
- data/lib/songbooks/version.rb +1 -1
- data/songbooks.gemspec +3 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ca632574ffa55e768046d6031870449a323a19
|
4
|
+
data.tar.gz: e305847777bb84d60183e829e298b89c822def42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c3034cbf4f59f04edb4ce36b0161899c01f005e5614f33eed660205a0fcad7e1397b1bed010d4e0ae1aaa3490f5d82128ec2bfe963e12cfdb49cffff839ffd
|
7
|
+
data.tar.gz: 9c59ec7de4d4cf77462bef044812551bbd91ebe0f6d5c9aaf59c8da46fb57a5a576ea4f614f01af00c391ce1fffd16eb00052d2f867abe90978617b02e6cb68a
|
data/lib/songbooks.rb
CHANGED
data/lib/songbooks/folder.rb
CHANGED
@@ -4,6 +4,10 @@ module Songbooks
|
|
4
4
|
class Folder
|
5
5
|
def initialize(path)
|
6
6
|
@path = Pathname.new(path)
|
7
|
+
|
8
|
+
initialize_songs
|
9
|
+
|
10
|
+
register_file_watcher
|
7
11
|
end
|
8
12
|
|
9
13
|
attr_reader :path
|
@@ -18,15 +22,50 @@ module Songbooks
|
|
18
22
|
|
19
23
|
private
|
20
24
|
|
25
|
+
def add_song(song)
|
26
|
+
songs_by_identifier[song.identifier] = song
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_song(song)
|
30
|
+
songs_by_identifier.delete(song.identifier)
|
31
|
+
end
|
32
|
+
|
21
33
|
def songs_by_identifier
|
22
|
-
@
|
34
|
+
@songs_by_identifier ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def songs_by_filename
|
38
|
+
@songs
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize_songs
|
42
|
+
@songs = chords_files.each_with_object({}) do |file_path, h|
|
23
43
|
song = Songbooks::Song.new(File.read(file_path))
|
24
|
-
|
44
|
+
add_song(song)
|
45
|
+
h[file_path] = song
|
25
46
|
end
|
26
47
|
end
|
27
48
|
|
28
49
|
def chords_files
|
29
50
|
Dir[@path.join('**', '*.txt')]
|
30
51
|
end
|
52
|
+
|
53
|
+
def register_file_watcher
|
54
|
+
listener = Listen.to(path.to_s, only: /\.txt$/) do |modified, added, removed|
|
55
|
+
(modified + added).each do |filename|
|
56
|
+
song = Songbooks::Song.new(File.read(filename))
|
57
|
+
songs_by_filename[filename] = song
|
58
|
+
add_song(song)
|
59
|
+
end
|
60
|
+
|
61
|
+
removed.each do |filename|
|
62
|
+
song = songs_by_filename[filename]
|
63
|
+
remove_song(song)
|
64
|
+
songs_by_filename.delete(filename)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
listener.start
|
69
|
+
end
|
31
70
|
end
|
32
71
|
end
|
data/lib/songbooks/version.rb
CHANGED
data/songbooks.gemspec
CHANGED
@@ -39,6 +39,9 @@ Gem::Specification.new do |spec|
|
|
39
39
|
# CLI
|
40
40
|
spec.add_dependency 'thor', '~> 0.19'
|
41
41
|
|
42
|
+
# File watchers
|
43
|
+
spec.add_dependency 'listen', '~> 3.1'
|
44
|
+
|
42
45
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
43
46
|
spec.add_development_dependency 'rake', '~> 10.0'
|
44
47
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: songbooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Exner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.19'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: listen
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.1'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.1'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: bundler
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|