restful_controller 0.0.3 → 0.0.4
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 +4 -4
- data/README.rdoc +14 -0
- data/lib/restful/base.rb +47 -7
- data/lib/restful/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b0d716631d6db9e787441b6ce1f5193e04c5fb
|
4
|
+
data.tar.gz: bbb4af70d8f7895d85064e26c86e74f6a3de3fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19658678112cc77d94191ebc2fbfdc2842512aa8af7b3aeb38a4c6fa59c51e63311d4374093911dee644f8cf84a884118181eabc31e208d47942f71ec9734d0
|
7
|
+
data.tar.gz: 5b0c97d26fb52801a45fcb52efadd1d6e0b6f8f5e7d973ca95d28914c28e64261cc66b3bf10bb84c50e55cb156ccbecfeead50e96596562408feba599d90b609
|
data/README.rdoc
CHANGED
@@ -143,6 +143,20 @@ proving a dual block for success and failure results from our action:
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
== Helper methods
|
147
|
+
Restful add a set of handy methods that allows it to play nice with Rails view inheritance.
|
148
|
+
|
149
|
+
These methods are:
|
150
|
+
|
151
|
+
# Let's assume that our model is Document
|
152
|
+
collection_(path|url) # will return /documents
|
153
|
+
edit_resource_(path|url)(object) # will return /documents/edit/1
|
154
|
+
new_resource_([ath|url) # will return /documents/new
|
155
|
+
|
156
|
+
resource_class # will return class definition Document
|
157
|
+
|
158
|
+
If you want to know how to take advantage of Rails View Inheritance then take a look at this document https://github.com/mariochavez/restful/wiki/View-Inheritance-with-Rails
|
159
|
+
|
146
160
|
== Bugs and feedback
|
147
161
|
Use issues at Github to report bugs or give feedback.
|
148
162
|
|
data/lib/restful/base.rb
CHANGED
@@ -35,6 +35,50 @@ module Restful
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
##
|
39
|
+
# Helper method that gives you access to the class of your model.
|
40
|
+
def resource_class
|
41
|
+
class_name
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Generic route path helper method to edit a model.
|
46
|
+
def edit_resource_path(object)
|
47
|
+
self.send "edit_#{class_name.model_name.singular_route_key}_path",
|
48
|
+
object
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Generic route url helper method to edit a model.
|
53
|
+
def edit_resource_url(object)
|
54
|
+
self.send "edit_#{class_name.model_name.singular_route_key}_url",
|
55
|
+
object
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Generic route path helper method for new model.
|
60
|
+
def new_resource_path
|
61
|
+
self.send "new_#{class_name.model_name.singular_route_key}_path"
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Generic route url helper method for new model.
|
66
|
+
def new_resource_url
|
67
|
+
self.send "new_#{class_name.model_name.singular_route_key}_url"
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# This is a helper method to get the object collection path.
|
72
|
+
def collection_path
|
73
|
+
self.send "#{class_name.model_name.route_key}_path"
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# This is a helper method to get the object collection url.
|
78
|
+
def collection_url
|
79
|
+
self.send "#{class_name.model_name.route_key}_url"
|
80
|
+
end
|
81
|
+
|
38
82
|
protected
|
39
83
|
##
|
40
84
|
# Return the instance variable name for a single object based on the model
|
@@ -117,12 +161,6 @@ module Restful
|
|
117
161
|
strong_params.call(params)
|
118
162
|
end
|
119
163
|
|
120
|
-
##
|
121
|
-
# This is a helper method to get the object collection path.
|
122
|
-
def collection_path
|
123
|
-
self.send "#{class_name.model_name.route_key}_path"
|
124
|
-
end
|
125
|
-
|
126
164
|
##
|
127
165
|
# This is a special method used by create and update actions that allows
|
128
166
|
# these methods to receive two blocks, success and failure blocks.
|
@@ -279,7 +317,9 @@ module Restful
|
|
279
317
|
|
280
318
|
setup_actions actions unless actions == :all
|
281
319
|
|
282
|
-
helper_method :collection, :resource
|
320
|
+
helper_method :collection, :resource, :resource_class,
|
321
|
+
:edit_resource_path, :edit_resource_url, :new_resource_path,
|
322
|
+
:new_resource_url, :collection_path, :collection_url
|
283
323
|
end
|
284
324
|
|
285
325
|
protected
|
data/lib/restful/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Alberto Chavez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|