faceted 1.0.1 → 1.0.2

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.
data/README.md CHANGED
@@ -78,6 +78,7 @@ Collectors are simply models that collect multiple instances of another model. A
78
78
  class Playlist
79
79
  include Faceted::Collector
80
80
  collects :musicians, :find_by => :genre_id
81
+ collects :deejays #implicit find_by, using 'playlist_id'
81
82
  end
82
83
  end
83
84
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
data/faceted.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "faceted"
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Ehmke", "Max Thom Stahl"]
@@ -19,14 +19,20 @@ module Faceted
19
19
 
20
20
  def collects(name, args={})
21
21
  @fields = [name]
22
- find_by = args[:find_by] ? args[:find_by] : "#{self.class.name.underscore.singularize}_id"
22
+ find_by = args[:find_by] ? args[:find_by] : "#{self.name.split('::')[-1].underscore.singularize}_id"
23
23
  @collects ||= {}
24
24
  @collects[name.downcase] = eval "#{scope}#{args[:class_name] || name.to_s.classify}"
25
25
  define_method :"#{name.downcase}" do
26
26
  objects(name.downcase.to_sym)
27
27
  end
28
- define_method :"#{name.downcase}_finder" do
29
- {"#{find_by}" => self.send(find_by)}
28
+ if args[:find_by].nil?
29
+ define_method :"#{name.downcase}_finder" do
30
+ {"#{find_by}" => self.id}
31
+ end
32
+ else
33
+ define_method :"#{name.downcase}_finder" do
34
+ {"#{find_by}" => self.send(find_by)}
35
+ end
30
36
  end
31
37
  self.send(:attr_accessor, find_by)
32
38
  end
@@ -59,10 +59,13 @@ module MyApi
59
59
 
60
60
  it 'initializes the associated objects in the correct namespace' do
61
61
  band = MyApi::Band.new(:birthplace_id => 1)
62
+ band.stub(:id) { 3 }
62
63
  MyApi::Musician.stub(:where) { [MyApi::Musician.new] }
63
64
  MyApi::Song.stub(:where) { [MyApi::Song.new] }
65
+ MyApi::Song.should_receive(:where).with('band_id' => 3)
64
66
  band.musicians.first.class.name.should == "MyApi::Musician"
65
67
  band.songs.first.class.name.should == "MyApi::Song"
68
+
66
69
  end
67
70
 
68
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faceted
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  segments:
183
183
  - 0
184
- hash: -4548707145106113177
184
+ hash: -4373279037322943472
185
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  none: false
187
187
  requirements: