chusaku 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: fd52c6a335647238e65651127426991f77a44941ab3edf41446b705c104c1e92
4
- data.tar.gz: 4f560a7d4c284fe6c07a8f992cace5ca12bd1e0bb4ef41156ebbc99d13539578
3
+ metadata.gz: cb896064bc711881c0b3efec1513838ec219d4a98f69643aa7a50214d092a942
4
+ data.tar.gz: b3409d3ce1b736b6290d8a122c4edeaceb88d9caa51c845fae0ad6d31d5401ee
5
5
  SHA512:
6
- metadata.gz: 78f1c90ee63e1a9dc4ca41d325f398771d80d4dd94ce6b208d93e9044ce19f58bf270347adfe729abe5d1673ee9a896bf64e45d1b597857a61f7407d071a4b9c
7
- data.tar.gz: 26f916c728c44b54ca2347546f6fa47da0b8526482433ed9d941071ceb4b9797f360b28bd25e597abe0b7cb6c44f8b9450d0cb9d11b2f201686aefd9e325fffe
6
+ metadata.gz: 759e9b4aaa8087e652248f349dc41fd340a117234d25be941c223a112e4a7080c122c268c77da37f098f7d53ec19e7e7a27c502abed0496fd758874a40366101
7
+ data.tar.gz: b527142c5b3e8dd08ea919ef8b90dfa3703c9580b2c9efcfd12cbedd56131975dd7473f0d5bfe612b007bb7f03ca07926f54ade8ae4ac58e12ce37de8c0db932
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Add comments above your Rails actions that look like:
8
8
 
9
9
  ```ruby
10
- # @route GET /waterlilies/:id (waterlily)
10
+ # @route [GET] /waterlilies/:id (waterlily)
11
11
  def show
12
12
  # ...
13
13
  end
@@ -8,11 +8,23 @@ module Chusaku
8
8
  #
9
9
  # {
10
10
  # 'users' => {
11
- # 'edit' => { verb: 'GET', path: '/users/:id', name: 'edit_user' },
12
- # 'update' => { verb: 'PUT', path: '/users', name: nil }
11
+ # 'edit' => {
12
+ # verbs: ['GET'],
13
+ # path: '/users/:id',
14
+ # name: 'edit_user'
15
+ # },
16
+ # 'update' => {
17
+ # verbs: ['PUT', 'PATCH'],
18
+ # path: '/users',
19
+ # name: nil
20
+ # }
13
21
  # },
14
22
  # 'empanadas' => {
15
- # 'create' => { verb: 'POST', path: '/empanadas', name: nil }
23
+ # 'create' => {
24
+ # verbs: ['POST'],
25
+ # path: '/empanadas',
26
+ # name: nil
27
+ # }
16
28
  # }
17
29
  # }
18
30
  #
@@ -22,18 +34,32 @@ module Chusaku
22
34
 
23
35
  Rails.application.routes.routes.each do |route|
24
36
  defaults = route.defaults
37
+ controller = defaults[:controller]
25
38
  action = defaults[:action]
26
39
 
27
- routes[defaults[:controller]] ||= {}
28
- routes[defaults[:controller]][action] =
29
- {
30
- verb: route.verb,
31
- path: route.path.spec.to_s.gsub('(.:format)', ''),
32
- name: route.name
33
- }
40
+ routes[controller] ||= {}
41
+ if routes[controller][action].nil?
42
+ routes[controller][action] = format_action(route)
43
+ else
44
+ routes[controller][action][:verbs].push(route.verb)
45
+ end
34
46
  end
35
47
 
36
48
  routes
37
49
  end
50
+
51
+ private
52
+
53
+ # Extract information of a given route.
54
+ #
55
+ # @param {ActionDispatch::Journey::Route} route
56
+ # @return {Hash}
57
+ def self.format_action(route)
58
+ {
59
+ verbs: [route.verb],
60
+ path: route.path.spec.to_s.gsub('(.:format)', ''),
61
+ name: route.name
62
+ }
63
+ end
38
64
  end
39
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chusaku
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/chusaku.rb CHANGED
@@ -75,10 +75,10 @@ module Chusaku
75
75
  # @param {Hash} action_info
76
76
  # @return {String}
77
77
  def self.annotate(action_info)
78
- verb = action_info[:verb]
78
+ verbs = action_info[:verbs]
79
79
  path = action_info[:path]
80
80
  name = action_info[:name]
81
- annotation = "@route #{verb} #{path}"
81
+ annotation = "@route [#{verbs.join(', ')}] #{path}"
82
82
  annotation += " (#{name})" unless name.nil?
83
83
  annotation
84
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chusaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nishiki Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-25 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler