flowmor_router 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a35be7196bc8e8a9a266166cb7e26183aec8acb7
4
- data.tar.gz: a50be83d19857e592851ea776cf26052697bedec
3
+ metadata.gz: 5593122f6cf3703bf1767a2538c409c075928f8d
4
+ data.tar.gz: d58371baeb36d8834c3f0f1433a619f8f3aa141a
5
5
  SHA512:
6
- metadata.gz: efacdcbb75d8389bbde761a58e37f052d08718c882c43eb79d0d769a01d49acc357b7662cef21164578929a7a568b6bdf54d77119e14dc6487cc65628906f51f
7
- data.tar.gz: 06153e994f65947566ca0701858b6c9ec727dd1195b413eb9210550c0e75aa7bae76f9aaac910448acf968ca8732a5499f56da5204964807adb20650b4fe99cb
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
- get router_class.route_path(record),
19
- to: router_class.controller_action,
20
- defaults: { id: record.id },
21
- as: router_class.route_name(record)
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 route_name record
222
- "#{route_name_prefix(record)}#{route_base_name}_#{route_name_suffix(record)}#{name(record)}".underscore.parameterize("_")
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
@@ -1,3 +1,3 @@
1
1
  module FlowmorRouter
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end