ituner 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ module ITuner
43
43
  nil
44
44
  end
45
45
 
46
- collection :sources
46
+ has_many :sources
47
47
 
48
48
  def library
49
49
  sources["Library"]
@@ -29,7 +29,15 @@ module ITuner
29
29
  end
30
30
  end
31
31
 
32
- def collection(name, app_name = name, &block)
32
+ def belongs_to(name, app_name)
33
+ define_method(name) do
34
+ parent_class = ITuner.const_get(name.to_s.capitalize)
35
+ app_parent = app_object.send(app_name).get
36
+ parent_class.new(app_parent) if app_parent
37
+ end
38
+ end
39
+
40
+ def has_many(name, app_name = name, &block)
33
41
  item_type = name.to_s.sub(/s$/,'').to_sym
34
42
  item_class = ITuner.const_get(item_type.to_s.capitalize)
35
43
  define_method(name) do
@@ -1,13 +1,16 @@
1
1
  require 'ituner/model'
2
2
  require 'ituner/track'
3
+ require 'ituner/playlist'
3
4
 
4
5
  module ITuner
5
6
 
6
7
  class Playlist < Model
7
8
 
8
- property :name
9
+ belongs_to :source, :container
9
10
 
10
- collection :tracks do
11
+ property :name
12
+
13
+ has_many :tracks do
11
14
 
12
15
  def clear
13
16
  app_collection.delete
@@ -6,8 +6,8 @@ module ITuner
6
6
  class Source < Model
7
7
 
8
8
  property :name
9
-
10
- collection :playlists do
9
+
10
+ has_many :playlists do
11
11
 
12
12
  def find_or_create(name)
13
13
  get(name) || create(:name => name)
@@ -15,7 +15,15 @@ module ITuner
15
15
 
16
16
  end
17
17
 
18
- collection :tracks
18
+ def main_playlist
19
+ playlists.detect { |playlist| playlist.name == self.name }
20
+ end
21
+
22
+ def search(*args)
23
+ main_playlist.search(*args)
24
+ end
25
+
26
+ has_many :tracks
19
27
 
20
28
  def music
21
29
  playlists["Music"]
@@ -4,6 +4,8 @@ module ITuner
4
4
 
5
5
  class Track < Model
6
6
 
7
+ belongs_to :playlist, :container
8
+
7
9
  property :name
8
10
  property :artist
9
11
  property :album
@@ -1,3 +1,3 @@
1
1
  module ITuner
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,6 +14,15 @@ describe ITuner::Playlist do
14
14
  @playlist.tracks.should be_kind_of(ITuner::Collection)
15
15
  end
16
16
 
17
+ describe "#source" do
18
+
19
+ it "returns the parent source" do
20
+ @playlist.source.should be_kind_of(ITuner::Source)
21
+ @playlist.source.name.should == "Library"
22
+ end
23
+
24
+ end
25
+
17
26
  describe "#search" do
18
27
 
19
28
  it "returns matching tracks" do
@@ -45,4 +45,21 @@ describe ITuner::Source do
45
45
 
46
46
  end
47
47
 
48
+ describe "#main_playlist" do
49
+
50
+ it "returns the main playlist" do
51
+ @source.main_playlist.should be_kind_of(ITuner::Playlist)
52
+ @source.main_playlist.name.should == @source.name
53
+ end
54
+
55
+ end
56
+
57
+ describe "#search" do
58
+
59
+ it "returns matching tracks" do
60
+ @source.search("Nirvana").map(&:name).should include("Smells Like Teen Spirit")
61
+ end
62
+
63
+ end
64
+
48
65
  end
@@ -22,7 +22,15 @@ describe ITuner::Track do
22
22
  it "has a uid" do
23
23
  @track.uid.should be_kind_of(Fixnum)
24
24
  end
25
-
25
+
26
+ describe "#playlist" do
27
+
28
+ it "returns the containing playlist" do
29
+ @track.playlist.should be_kind_of(ITuner::Playlist)
30
+ end
31
+
32
+ end
33
+
26
34
  it "can be played" do
27
35
  @track.play
28
36
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ituner
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Williams
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-21 00:00:00 +11:00
13
+ date: 2011-03-31 00:00:00 +11:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency