faceted 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
data/faceted.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "faceted"
8
- s.version = "1.1.1"
8
+ s.version = "1.2.0"
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"]
12
- s.date = "2012-12-20"
12
+ s.date = "2013-02-25"
13
13
  s.description = "Faceted provides set of tools, patterns, and modules for use in API implementations."
14
14
  s.email = "corey@trunkclub.com"
15
15
  s.extra_rdoc_files = [
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.homepage = "http://github.com/trunkclub/faceted"
41
41
  s.licenses = ["MIT"]
42
42
  s.require_paths = ["lib"]
43
- s.rubygems_version = "1.8.23"
43
+ s.rubygems_version = "1.8.24"
44
44
  s.summary = "Faceted provides set of tools, patterns, and modules for use in API implementations."
45
45
 
46
46
  if s.respond_to? :specification_version then
@@ -75,7 +75,7 @@ module Faceted
75
75
 
76
76
  def object
77
77
  return unless self.class.klass
78
- @object ||= self.id ? self.class.klass.find(self.id) : self.class.klass.new
78
+ @object ||= self.class.klass.where(find_by => self.send(find_by)) || self.class.klass.new
79
79
  end
80
80
 
81
81
  def object=(obj)
@@ -24,6 +24,9 @@ module Faceted
24
24
  def presents(name, args={})
25
25
  class_name = args[:class_name] || name.to_s.classify
26
26
  @presents = eval(class_name)
27
+ define_method :find_by do
28
+ args[:find_by] || :id
29
+ end
27
30
  define_method :"#{class_name.downcase}" do
28
31
  object
29
32
  end
@@ -14,6 +14,13 @@ class Birthplace # another make-believe AR model
14
14
  def reload; self; end
15
15
  end
16
16
 
17
+ class Album # and yet another make-believe AR model
18
+ attr_accessor :id, :name
19
+ def initialize(params={}); params.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}; end
20
+ def attributes; {:id => self.id, :name => self.name}; end
21
+ def reload; self; end
22
+ end
23
+
17
24
  module MyApi
18
25
 
19
26
  class Birthplace
@@ -32,15 +39,21 @@ module MyApi
32
39
  field :alive
33
40
  end
34
41
 
42
+ class Album
43
+ include Faceted::Presenter
44
+ presents :album, :find_by => :name
45
+ field :name
46
+ end
47
+
35
48
  describe Musician do
36
49
 
37
50
  before do
38
51
 
39
52
  @ar_musician = ::Musician.new(:id => 1, :name => 'Johnny Cash', :rating => 'Good', :alive => false)
40
- ::Musician.stub(:find) { @ar_musician }
53
+ ::Musician.stub(:where) { @ar_musician }
41
54
 
42
55
  @ar_birthplace = ::Birthplace.new(:id => 1, :city => 'Kingsland', :state => 'Arkansas')
43
- ::Birthplace.stub(:find) { @ar_birthplace }
56
+ ::Birthplace.stub(:where) { @ar_birthplace }
44
57
 
45
58
  end
46
59
 
@@ -110,6 +123,13 @@ module MyApi
110
123
  musician.birthplace.city.should == 'Kingsland'
111
124
  end
112
125
 
126
+ it 'initializes the associated object finding by a specified key' do
127
+ @ar_album = ::Album.new(:id => 1, :name => 'Greatest Hits')
128
+ ::Album.stub(:where) { @ar_album }
129
+ album = MyApi::Album.new(:name => 'Greatest Hits')
130
+ album.id.should == 1
131
+ end
132
+
113
133
  end
114
134
 
115
135
  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.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-20 00:00:00.000000000 Z
13
+ date: 2013-02-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  segments:
216
216
  - 0
217
- hash: 2921058822992473011
217
+ hash: 4579976774321596650
218
218
  required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  none: false
220
220
  requirements:
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  requirements: []
225
225
  rubyforge_project:
226
- rubygems_version: 1.8.23
226
+ rubygems_version: 1.8.24
227
227
  signing_key:
228
228
  specification_version: 3
229
229
  summary: Faceted provides set of tools, patterns, and modules for use in API implementations.