chusaku 0.6.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -16
- data/lib/chusaku/routes.rb +27 -2
- data/lib/chusaku/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8295890eb74a89ebc38a8651d4a5d5c8f87112a7336658e8dea1117d525a1a1a
|
4
|
+
data.tar.gz: 6cb5e53d089e0996c0b6b7e9e0b7128902fa60bc54c3f458d737e56e5c5a7a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885022690966e86943484029fc383572ea254487d18f4b9f43ac1fa225e99b5cfd75f8e7f1787929cf7bbccae872ce63149a260ec5c5ef00f8e1e61added54db
|
7
|
+
data.tar.gz: 2d6151abb44a539dbd662af25f8f961a21ec72c2bd012268eff9a749da4affbe02589f38036a3926dadb430340c6fa4d84a2ceff052e4c1ca1045723bd1b8600
|
data/README.md
CHANGED
@@ -61,25 +61,10 @@ Usage: chusaku [options]
|
|
61
61
|
```
|
62
62
|
|
63
63
|
|
64
|
-
## Pre-commit Hook
|
65
|
-
|
66
|
-
Here's an example setup that you could use for automating Chusaku as a Git hook
|
67
|
-
with the [Lefthook](https://github.com/Arkweid/lefthook) gem.
|
68
|
-
|
69
|
-
```yaml
|
70
|
-
pre-commit:
|
71
|
-
commands:
|
72
|
-
chusaku:
|
73
|
-
run: eval "! git diff --staged --name-only | grep -q 'routes.rb' && exit 0 || bundle exec chusaku --exit-with-error-on-annotation"
|
74
|
-
```
|
75
|
-
|
76
|
-
This example config only runs Chusaku if `routes.rb` was modified.
|
77
|
-
|
78
|
-
|
79
64
|
## Development
|
80
65
|
|
81
66
|
Read the blog post explaining how the gem works at a high level:
|
82
|
-
https://nshki.com/chusaku-a-controller-annotation-gem
|
67
|
+
https://nshki.com/chusaku-a-controller-annotation-gem.
|
83
68
|
|
84
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
85
70
|
`bundle exec rake test` to run the tests. You can also run `bin/console` for an
|
data/lib/chusaku/routes.rb
CHANGED
@@ -98,11 +98,36 @@ module Chusaku
|
|
98
98
|
def backfill_routes(routes)
|
99
99
|
paths = {}
|
100
100
|
|
101
|
+
# Map paths to their verbs and names.
|
102
|
+
#
|
103
|
+
# Resulting hash looks like:
|
104
|
+
#
|
105
|
+
# ```ruby
|
106
|
+
# {
|
107
|
+
# "/users/:id" => {
|
108
|
+
# "GET" => "edit_user",
|
109
|
+
# "PATCH" => "edit_user"
|
110
|
+
# }
|
111
|
+
# }
|
112
|
+
# ````
|
101
113
|
routes.each do |_controller, actions|
|
102
114
|
actions.each do |_action, data|
|
103
115
|
data.each do |datum|
|
104
|
-
paths[datum[:path]] ||=
|
105
|
-
datum[:
|
116
|
+
paths[datum[:path]] ||= {}
|
117
|
+
paths[datum[:path]][datum[:verb]] ||= datum[:name]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Backfill names for routes that don't have them.
|
123
|
+
#
|
124
|
+
# First try to match based on the path and verb. If that doesn't work,
|
125
|
+
# try to match based on the path alone.
|
126
|
+
routes.each do |_controller, actions|
|
127
|
+
actions.each do |_action, data|
|
128
|
+
data.each do |datum|
|
129
|
+
datum[:name] ||= paths.dig(datum[:path], datum[:verb])
|
130
|
+
datum[:name] ||= paths[datum[:path]]&.values&.compact&.first
|
106
131
|
end
|
107
132
|
end
|
108
133
|
end
|
data/lib/chusaku/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nishiki Liu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,7 +113,7 @@ metadata:
|
|
113
113
|
homepage_uri: https://github.com/nshki/chusaku
|
114
114
|
source_code_uri: https://github.com/nshki/chusaku
|
115
115
|
changelog_uri: https://github.com/nshki/chusaku
|
116
|
-
post_install_message:
|
116
|
+
post_install_message:
|
117
117
|
rdoc_options: []
|
118
118
|
require_paths:
|
119
119
|
- lib
|
@@ -128,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
131
|
+
rubygems_version: 3.4.17
|
132
|
+
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Annotate your Rails controllers with route info.
|
135
135
|
test_files: []
|