kagu 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/kagu/attributes_initializer.rb +11 -7
- data/lib/kagu/error.rb +15 -0
- data/lib/kagu/library.rb +2 -2
- data/lib/kagu/playlists.rb +2 -1
- data/lib/kagu/track.rb +1 -1
- data/lib/kagu/tracks.rb +2 -1
- data/lib/kagu.rb +1 -1
- data/spec/kagu/error_spec.rb +40 -0
- data/spec/kagu/library_spec.rb +2 -2
- data/spec/kagu/playlist_spec.rb +1 -1
- data/spec/kagu/playlists_spec.rb +6 -2
- data/spec/kagu/track_spec.rb +6 -6
- data/spec/kagu/tracks_spec.rb +6 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d4e5df146ca66edf6bf1cbe4f640dbfddd33f3
|
4
|
+
data.tar.gz: d2e1ee38ab2c17b049fe58fbbfbfadb7fe271dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ec012cf7b2b9aafee03ebe394b4e2f901809fa023ac888ba0ddefd7b71a552e16bf0e989ee355fbb3a018578eca4e8dd8c37fb4df859ca42fd6bf9c4810ec96
|
7
|
+
data.tar.gz: 0f8848137e743a15f8e6ccf97f77817d100af3bb658c168fcec74f0564d315743c87e837ed4ec2720668eafa5e4ce6c1327385f678f885f856d1d22724ad6c3a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,12 +1,16 @@
|
|
1
|
-
module
|
1
|
+
module Kagu
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module AttributesInitializer
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
attributes.each do |name, value|
|
7
|
+
send("#{name}=", value) if respond_to?("#{name}=", true)
|
8
|
+
end
|
9
|
+
self.class.const_get(:MANDATORY_ATTRIBUTES).each do |attribute|
|
10
|
+
raise Error.new("#{self.class}##{attribute} is mandatory") if send(attribute).nil?
|
11
|
+
end
|
9
12
|
end
|
13
|
+
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
data/lib/kagu/error.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Kagu
|
2
|
+
|
3
|
+
class Error < StandardError
|
4
|
+
|
5
|
+
attr_reader :original
|
6
|
+
|
7
|
+
def initialize(message)
|
8
|
+
@original = message.is_a?(Exception) ? message : nil
|
9
|
+
message = original.message if original.is_a?(Exception)
|
10
|
+
super(message.to_s.squish.presence)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/kagu/library.rb
CHANGED
@@ -2,7 +2,7 @@ module Kagu
|
|
2
2
|
|
3
3
|
class Library
|
4
4
|
|
5
|
-
PATH = "#{ENV['HOME']}/Music/iTunes/iTunes Music Library.xml"
|
5
|
+
PATH = File.expand_path("#{ENV['HOME']}/Music/iTunes/iTunes Music Library.xml")
|
6
6
|
|
7
7
|
attr_reader :path
|
8
8
|
|
@@ -21,7 +21,7 @@ module Kagu
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def path=(path)
|
24
|
-
raise
|
24
|
+
raise Error.new("No such file: #{path.inspect}") unless File.file?(path)
|
25
25
|
@path = path
|
26
26
|
end
|
27
27
|
|
data/lib/kagu/playlists.rb
CHANGED
@@ -7,7 +7,8 @@ module Kagu
|
|
7
7
|
attr_reader :library
|
8
8
|
|
9
9
|
def initialize(library)
|
10
|
-
|
10
|
+
raise ArgumentError.new("#{self.class}#library must be a library, #{library.inspect} given") unless library.is_a?(Library)
|
11
|
+
@library = library
|
11
12
|
end
|
12
13
|
|
13
14
|
def each(&block)
|
data/lib/kagu/track.rb
CHANGED
data/lib/kagu/tracks.rb
CHANGED
@@ -7,7 +7,8 @@ module Kagu
|
|
7
7
|
attr_reader :library
|
8
8
|
|
9
9
|
def initialize(library)
|
10
|
-
|
10
|
+
raise ArgumentError.new("#{self.class}#library must be a library, #{library.inspect} given") unless library.is_a?(Library)
|
11
|
+
@library = library
|
11
12
|
end
|
12
13
|
|
13
14
|
def each(&block)
|
data/lib/kagu.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'active_support/core_ext'
|
2
2
|
require 'byebug' if ENV['DEBUGGER']
|
3
|
-
require 'fileutils'
|
4
3
|
require 'htmlentities'
|
5
4
|
|
6
5
|
lib_path = "#{__dir__}/kagu"
|
7
6
|
|
8
7
|
require "#{lib_path}/attributes_initializer"
|
8
|
+
require "#{lib_path}/error"
|
9
9
|
require "#{lib_path}/library"
|
10
10
|
require "#{lib_path}/playlist"
|
11
11
|
require "#{lib_path}/playlists"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kagu::Error do
|
4
|
+
|
5
|
+
let(:error) { Kagu::Error.new('BAM!') }
|
6
|
+
let(:original) { StandardError.new('BIM!') }
|
7
|
+
|
8
|
+
describe '#message' do
|
9
|
+
|
10
|
+
it 'is message set at initialization' do
|
11
|
+
expect(error.message).to eq('BAM!')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'message is squished' do
|
15
|
+
expect(Kagu::Error.new(" hello \n world").message).to eq('hello world')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'default one if blank' do
|
19
|
+
expect(Kagu::Error.new(" ").message).to eq('Kagu::Error')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#original' do
|
25
|
+
|
26
|
+
it 'is nil by default' do
|
27
|
+
expect(error.original).to be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'is exception given at initialization' do
|
31
|
+
expect(Kagu::Error.new(original).original).to be(original)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'sets message from original' do
|
35
|
+
expect(Kagu::Error.new(original).message).to eq('BIM!')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/kagu/library_spec.rb
CHANGED
@@ -13,13 +13,13 @@ describe Kagu::Library do
|
|
13
13
|
it 'raise an error if directory' do
|
14
14
|
expect {
|
15
15
|
Kagu::Library.new('/tmp')
|
16
|
-
}.to raise_error(
|
16
|
+
}.to raise_error(Kagu::Error, 'No such file: "/tmp"')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raise an error if file can't be found" do
|
20
20
|
expect {
|
21
21
|
Kagu::Library.new('/tmp/bar.foo.baz')
|
22
|
-
}.to raise_error(
|
22
|
+
}.to raise_error(Kagu::Error, 'No such file: "/tmp/bar.foo.baz"')
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
data/spec/kagu/playlist_spec.rb
CHANGED
data/spec/kagu/playlists_spec.rb
CHANGED
@@ -30,12 +30,16 @@ describe Kagu::Playlists do
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
-
describe '#
|
33
|
+
describe '#library' do
|
34
|
+
|
35
|
+
it 'is library given at initialization' do
|
36
|
+
expect(playlists.library).to be(library)
|
37
|
+
end
|
34
38
|
|
35
39
|
it 'raise an error if library is nil' do
|
36
40
|
expect {
|
37
41
|
Kagu::Playlists.new(nil)
|
38
|
-
}.to raise_error('Kagu::Playlists#library must be a library, nil given')
|
42
|
+
}.to raise_error(ArgumentError, 'Kagu::Playlists#library must be a library, nil given')
|
39
43
|
end
|
40
44
|
|
41
45
|
end
|
data/spec/kagu/track_spec.rb
CHANGED
@@ -85,7 +85,7 @@ describe Kagu::Track do
|
|
85
85
|
it 'raise an error if not specified' do
|
86
86
|
expect {
|
87
87
|
Kagu::Track.new(attributes.except(:added_at))
|
88
|
-
}.to raise_error('Kagu::Track#added_at is mandatory')
|
88
|
+
}.to raise_error(Kagu::Error, 'Kagu::Track#added_at is mandatory')
|
89
89
|
end
|
90
90
|
|
91
91
|
end
|
@@ -142,7 +142,7 @@ describe Kagu::Track do
|
|
142
142
|
it 'raise an error if not specified' do
|
143
143
|
expect {
|
144
144
|
Kagu::Track.new(attributes.except(:id))
|
145
|
-
}.to raise_error('Kagu::Track#id is mandatory')
|
145
|
+
}.to raise_error(Kagu::Error, 'Kagu::Track#id is mandatory')
|
146
146
|
end
|
147
147
|
|
148
148
|
end
|
@@ -167,7 +167,7 @@ describe Kagu::Track do
|
|
167
167
|
it 'raise an error if not specified' do
|
168
168
|
expect {
|
169
169
|
Kagu::Track.new(attributes.except(:length))
|
170
|
-
}.to raise_error('Kagu::Track#length is mandatory')
|
170
|
+
}.to raise_error(Kagu::Error, 'Kagu::Track#length is mandatory')
|
171
171
|
end
|
172
172
|
|
173
173
|
end
|
@@ -182,19 +182,19 @@ describe Kagu::Track do
|
|
182
182
|
it 'raise an error if not specified' do
|
183
183
|
expect {
|
184
184
|
Kagu::Track.new(attributes.except(:path))
|
185
|
-
}.to raise_error('Kagu::Track#path is mandatory')
|
185
|
+
}.to raise_error(Kagu::Error, 'Kagu::Track#path is mandatory')
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'raise an error if not found' do
|
189
189
|
expect {
|
190
190
|
Kagu::Track.new(attributes.merge(path: '/tmp/bar.mp3'))
|
191
|
-
}.to raise_error('No such file: "/tmp/bar.mp3"')
|
191
|
+
}.to raise_error(Kagu::Error, 'No such file: "/tmp/bar.mp3"')
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'raise an error if not a file' do
|
195
195
|
expect {
|
196
196
|
Kagu::Track.new(attributes.merge(path: '/tmp'))
|
197
|
-
}.to raise_error('No such file: "/tmp"')
|
197
|
+
}.to raise_error(Kagu::Error, 'No such file: "/tmp"')
|
198
198
|
end
|
199
199
|
|
200
200
|
end
|
data/spec/kagu/tracks_spec.rb
CHANGED
@@ -39,12 +39,16 @@ describe Kagu::Tracks do
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
describe '#
|
42
|
+
describe '#library' do
|
43
|
+
|
44
|
+
it 'is library given at initialization' do
|
45
|
+
expect(tracks.library).to be(library)
|
46
|
+
end
|
43
47
|
|
44
48
|
it 'raise an error if library is nil' do
|
45
49
|
expect {
|
46
50
|
Kagu::Tracks.new(nil)
|
47
|
-
}.to raise_error('Kagu::Tracks#library must be a library, nil given')
|
51
|
+
}.to raise_error(ArgumentError, 'Kagu::Tracks#library must be a library, nil given')
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kagu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Toulotte
|
@@ -126,11 +126,13 @@ files:
|
|
126
126
|
- kagu.gemspec
|
127
127
|
- lib/kagu.rb
|
128
128
|
- lib/kagu/attributes_initializer.rb
|
129
|
+
- lib/kagu/error.rb
|
129
130
|
- lib/kagu/library.rb
|
130
131
|
- lib/kagu/playlist.rb
|
131
132
|
- lib/kagu/playlists.rb
|
132
133
|
- lib/kagu/track.rb
|
133
134
|
- lib/kagu/tracks.rb
|
135
|
+
- spec/kagu/error_spec.rb
|
134
136
|
- spec/kagu/library_spec.rb
|
135
137
|
- spec/kagu/playlist_spec.rb
|
136
138
|
- spec/kagu/playlists_spec.rb
|
@@ -162,6 +164,7 @@ signing_key:
|
|
162
164
|
specification_version: 4
|
163
165
|
summary: API for iTunes
|
164
166
|
test_files:
|
167
|
+
- spec/kagu/error_spec.rb
|
165
168
|
- spec/kagu/library_spec.rb
|
166
169
|
- spec/kagu/playlist_spec.rb
|
167
170
|
- spec/kagu/playlists_spec.rb
|