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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3c550bd81fd6f184ccafb6017616b794678f6b6
4
- data.tar.gz: 3b68b821f9628595d751df1398c95fd18d4cabca
3
+ metadata.gz: 51ca632574ffa55e768046d6031870449a323a19
4
+ data.tar.gz: e305847777bb84d60183e829e298b89c822def42
5
5
  SHA512:
6
- metadata.gz: 2857a5dbc1a3701d5cd9b69871e29409764f9779ee402dbafc6f48203a8db82918d753d30f0cfba14e1fd6dabdf81d95e3027777c90fdcacacffb68b1276bc49
7
- data.tar.gz: ab5e6dff8c0d559d2359447075b2ff755784452e766f6e6c0d52c11cbbc6306f7763a3125388b94d3a530240773d4ccc1b82cd3b9b89ac2ffbe4d8cf867515f4
6
+ metadata.gz: 89c3034cbf4f59f04edb4ce36b0161899c01f005e5614f33eed660205a0fcad7e1397b1bed010d4e0ae1aaa3490f5d82128ec2bfe963e12cfdb49cffff839ffd
7
+ data.tar.gz: 9c59ec7de4d4cf77462bef044812551bbd91ebe0f6d5c9aaf59c8da46fb57a5a576ea4f614f01af00c391ce1fffd16eb00052d2f867abe90978617b02e6cb68a
@@ -7,6 +7,7 @@ module Songbooks
7
7
  require 'sinatra/prawn'
8
8
  require 'sinatra/jbuilder'
9
9
  require 'json'
10
+ require 'listen'
10
11
 
11
12
  # Ruby requires
12
13
  require 'pathname'
@@ -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
- @songs ||= chords_files.each_with_object({}) do |file_path, h|
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
- h[song.identifier] = song
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
@@ -1,3 +1,3 @@
1
1
  module Songbooks
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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.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-23 00:00:00.000000000 Z
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