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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8cfd404d70114c5ab0432216ae8d4b1e978357c
4
- data.tar.gz: c07c6fa355ab50c7bd1033de65cd4495b5fb11db
3
+ metadata.gz: e5d4e5df146ca66edf6bf1cbe4f640dbfddd33f3
4
+ data.tar.gz: d2e1ee38ab2c17b049fe58fbbfbfadb7fe271dbb
5
5
  SHA512:
6
- metadata.gz: 23c65772592525da40e5ebc004f6a98f812bc91da10d88a1301de5b925bbee511e88491615a20555e39a0538390a545c06ca2b34dc71242d7dd5757c10e683f5
7
- data.tar.gz: d0c149fb4d705457b6b4a4760c0b9519b18ad77b8743f6597a389633dd00b5f2c3eaba33ec5279d94efc73e25143e7eaa0be3fe1de5341229575674a18b4bc2a
6
+ metadata.gz: 4ec012cf7b2b9aafee03ebe394b4e2f901809fa023ac888ba0ddefd7b71a552e16bf0e989ee355fbb3a018578eca4e8dd8c37fb4df859ca42fd6bf9c4810ec96
7
+ data.tar.gz: 0f8848137e743a15f8e6ccf97f77817d100af3bb658c168fcec74f0564d315743c87e837ed4ec2720668eafa5e4ce6c1327385f678f885f856d1d22724ad6c3a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,12 +1,16 @@
1
- module AttributesInitializer
1
+ module Kagu
2
2
 
3
- def initialize(attributes = {})
4
- attributes.each do |name, value|
5
- send("#{name}=", value) if respond_to?("#{name}=", true)
6
- end
7
- self.class.const_get(:MANDATORY_ATTRIBUTES).each do |attribute|
8
- raise("#{self.class}##{attribute} is mandatory") if send(attribute).nil?
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 IOError.new("No such file: #{path.inspect}") unless File.file?(path)
24
+ raise Error.new("No such file: #{path.inspect}") unless File.file?(path)
25
25
  @path = path
26
26
  end
27
27
 
@@ -7,7 +7,8 @@ module Kagu
7
7
  attr_reader :library
8
8
 
9
9
  def initialize(library)
10
- @library = library.is_a?(Library) ? library : raise("#{self.class}#library must be a library, #{library.inspect} given")
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
@@ -11,7 +11,7 @@ module Kagu
11
11
 
12
12
  def initialize(attributes = {})
13
13
  super
14
- raise("No such file: #{path.inspect}") unless File.file?(path)
14
+ raise Error.new("No such file: #{path.inspect}") unless File.file?(path)
15
15
  end
16
16
 
17
17
  def <=>(other)
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
- @library = library.is_a?(Library) ? library : raise("#{self.class}#library must be a library, #{library.inspect} given")
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
@@ -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(IOError, 'No such file: "/tmp"')
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(IOError, 'No such file: "/tmp/bar.foo.baz"')
22
+ }.to raise_error(Kagu::Error, 'No such file: "/tmp/bar.foo.baz"')
23
23
  end
24
24
 
25
25
  end
@@ -42,7 +42,7 @@ describe Kagu::Playlist do
42
42
  it 'is mandatory' do
43
43
  expect {
44
44
  Kagu::Playlist.new(name: ' ')
45
- }.to raise_error('Kagu::Playlist#name is mandatory')
45
+ }.to raise_error(Kagu::Error, 'Kagu::Playlist#name is mandatory')
46
46
  end
47
47
 
48
48
  end
@@ -30,12 +30,16 @@ describe Kagu::Playlists do
30
30
 
31
31
  end
32
32
 
33
- describe '#initialize' do
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
@@ -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
@@ -39,12 +39,16 @@ describe Kagu::Tracks do
39
39
 
40
40
  end
41
41
 
42
- describe '#initialize' do
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.0
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