flowmor_router 0.2.4 → 0.2.5
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.md +8 -0
- data/config/routes.rb +14 -4
- data/lib/flowmor_router/router_classes.rb +7 -2
- data/lib/flowmor_router/version.rb +1 -1
- data/test/dummy/log/test.log +14320 -0
- data/test/router_classes_test.rb +26 -0
- 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: 5593122f6cf3703bf1767a2538c409c075928f8d
|
4
|
+
data.tar.gz: d58371baeb36d8834c3f0f1433a619f8f3aa141a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eaa442181928ffec79244c79ed12dca18dd7f4fc4c92a9af20a74668dc5f0b7a44fffaf88a93025bd60810dc8281e5bdc1a16b5a8a9d404a1b2d2cdda1909f9
|
7
|
+
data.tar.gz: f6b2780348cf9ed15a358af60290224fce98f9805bba8a2da98141aa1e587a63ee771bdecc3bb33348d4fdaab3a5ac4ca708d28095196653022a6a30215bd957
|
data/README.md
CHANGED
@@ -287,6 +287,14 @@ class PostCategory < ActiveRecord::Base
|
|
287
287
|
end
|
288
288
|
```
|
289
289
|
|
290
|
+
The above assumes only a GET action for the route. To have multiple verbs on the route, declare controller_action with a hash:
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
class Post < ActiveRecord::Base
|
294
|
+
acts_as_routable controller_action: { get: "blog#show", post: "blog#update" }
|
295
|
+
end
|
296
|
+
```
|
297
|
+
|
290
298
|
To change how the route and route name are constructed (say you have Post that belongs_to PostCategory and need to avoid naming collision should two posts have same title, but belong to different categories):
|
291
299
|
|
292
300
|
```ruby
|
data/config/routes.rb
CHANGED
@@ -15,10 +15,20 @@ Rails.application.routes.draw do
|
|
15
15
|
Rails.logger.debug "FlowmorRouter MODEL: #{router_class.model.name}"
|
16
16
|
router_class.routable.each do |record|
|
17
17
|
Rails.logger.debug "FlowmorRouter ROUTING: #{router_class.route_path(record)} to: #{router_class.controller_action} defaults: { id: #{record.id} } as: #{router_class.route_name(record)}"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
if router_class.controller_action.is_a? String
|
19
|
+
get router_class.route_path(record),
|
20
|
+
to: router_class.controller_action,
|
21
|
+
defaults: { id: record.id },
|
22
|
+
as: router_class.route_name(record)
|
23
|
+
elsif router_class.controller_action.is_a? Hash
|
24
|
+
router_class.controller_action.each_pair do |verb, action|
|
25
|
+
match router_class.route_path(record),
|
26
|
+
to: action,
|
27
|
+
defaults: { id: record.id },
|
28
|
+
via: verb,
|
29
|
+
as: "#{router_class.route_name(record, verb)}"
|
30
|
+
end
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
@@ -218,8 +218,13 @@ module FlowmorRouter
|
|
218
218
|
"/" + route_prefix(record).join("/")
|
219
219
|
end
|
220
220
|
|
221
|
-
def
|
222
|
-
"#{
|
221
|
+
def verb_prefix verb
|
222
|
+
return "#{verb}_" if verb
|
223
|
+
"#{controller_action.keys.first}_" if controller_action.is_a? Hash
|
224
|
+
end
|
225
|
+
|
226
|
+
def route_name record, verb=nil
|
227
|
+
"#{verb_prefix(verb)}#{route_name_prefix(record)}#{route_base_name}_#{route_name_suffix(record)}#{name(record)}".underscore.parameterize("_")
|
223
228
|
end
|
224
229
|
|
225
230
|
def route_path record
|