golden_retriever 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -1
- data/lib/golden_retriever.rb +8 -1
- data/test/restful_controller_test.rb +16 -0
- data/test/teststrap.rb +4 -0
- metadata +2 -2
data/README
CHANGED
@@ -5,7 +5,9 @@ Instructions:
|
|
5
5
|
|
6
6
|
script/plugin git://github.com/DouglasMeyer/golden_retriever.git
|
7
7
|
And add "require GoldenRetriever" to the controllers for which you want your
|
8
|
-
resources automatically retrieved
|
8
|
+
resources automatically retrieved, and the resoures will be loaded under their
|
9
|
+
names. You can also define "resource_find_method" to specify a different find
|
10
|
+
method (like :find_by_name).
|
9
11
|
|
10
12
|
Example:
|
11
13
|
|
@@ -29,4 +31,11 @@ class PostsController < ApplicationController
|
|
29
31
|
# @post will be the same as @user.posts.build
|
30
32
|
render :json => @post
|
31
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def resource_find_method(model_name)
|
38
|
+
model_name == 'post' ? :find_by_name : :find
|
39
|
+
end
|
40
|
+
|
32
41
|
end
|
data/lib/golden_retriever.rb
CHANGED
@@ -2,6 +2,13 @@ module GoldenRetriever
|
|
2
2
|
|
3
3
|
def self.included(controller)
|
4
4
|
controller.before_filter :load_resource
|
5
|
+
controller.extend ClassMethod
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethod
|
9
|
+
def resource_find_method(resource)
|
10
|
+
:find
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
14
|
private
|
@@ -15,7 +22,7 @@ private
|
|
15
22
|
parent.send(singular_name.pluralize)
|
16
23
|
else
|
17
24
|
singular_name.camelize.constantize
|
18
|
-
end.
|
25
|
+
end.send(self.class.resource_find_method(singular_name), params[key])
|
19
26
|
instance_variable_set("@#{singular_name}", object)
|
20
27
|
parent = object
|
21
28
|
end
|
@@ -50,4 +50,20 @@ context "Restful Controller" do
|
|
50
50
|
end.equals(:new)
|
51
51
|
end
|
52
52
|
|
53
|
+
context "with the method :resource_find_method" do
|
54
|
+
setup do
|
55
|
+
topic.instance_eval do
|
56
|
+
def resource_find_method(name)
|
57
|
+
"find_#{name}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
topic.action_name = 'show'
|
61
|
+
topic.new.send :load_resource
|
62
|
+
end
|
63
|
+
|
64
|
+
should "load resource using the method's response" do
|
65
|
+
FakePost.find_fake_post_called?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
53
69
|
end
|
data/test/teststrap.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: golden_retriever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DouglasMeyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-03 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|