chusaku 0.6.1 → 1.1.0
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 +7 -21
- data/lib/chusaku/cli.rb +12 -0
- data/lib/chusaku/routes.rb +27 -2
- data/lib/chusaku/version.rb +1 -1
- data/lib/chusaku.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: 62bb838dd76c648a120303c3a0bde8c67ea7232f90accb9f3e739a3b69764026
|
4
|
+
data.tar.gz: 9af1726825550cb4ce7d642e6a80217b8810cb6a56e8703c6d7f4f23a8643f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0baeb0a41404f911ef11b3d12709773a44ecc18aa542f5dcb854e1b67023b7fd79f640d10d7d8a4368121a33714327c5120ed701c9a67c238537023db78603e7
|
7
|
+
data.tar.gz: 1e5026ac8d35af5ff8c5d8c02d32d7d634716966dad3a61947398ee870203795ff91286bb43b7daf6802c4bace3df42b1ffb325c130e88b1fe26495d72100118
|
data/README.md
CHANGED
@@ -52,34 +52,20 @@ Chusaku has some flags available for use as well:
|
|
52
52
|
```
|
53
53
|
$ bundle exec chusaku --help
|
54
54
|
Usage: chusaku [options]
|
55
|
-
--dry-run
|
56
|
-
--exit-with-error-on-annotation
|
57
|
-
|
58
|
-
--verbose
|
59
|
-
-v, --version
|
60
|
-
-h, --help
|
61
|
-
```
|
62
|
-
|
63
|
-
|
64
|
-
## Pre-commit Hook
|
55
|
+
--dry-run Run without file modifications
|
56
|
+
--exit-with-error-on-annotation Fail if any file was annotated
|
57
|
+
-c, --controllers-pattern=GLOB Specify alternative controller files glob pattern
|
58
|
+
--verbose Print all annotations
|
59
|
+
-v, --version Show Chusaku version number and quit
|
60
|
+
-h, --help Show this help message and quit
|
65
61
|
|
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
62
|
```
|
75
63
|
|
76
|
-
This example config only runs Chusaku if `routes.rb` was modified.
|
77
|
-
|
78
64
|
|
79
65
|
## Development
|
80
66
|
|
81
67
|
Read the blog post explaining how the gem works at a high level:
|
82
|
-
https://nshki.com/chusaku-a-controller-annotation-gem
|
68
|
+
https://nshki.com/chusaku-a-controller-annotation-gem.
|
83
69
|
|
84
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
85
71
|
`bundle exec rake test` to run the tests. You can also run `bin/console` for an
|
data/lib/chusaku/cli.rb
CHANGED
@@ -52,8 +52,10 @@ module Chusaku
|
|
52
52
|
def optparser
|
53
53
|
OptionParser.new do |opts|
|
54
54
|
opts.banner = "Usage: chusaku [options]"
|
55
|
+
opts.set_summary_width(35)
|
55
56
|
add_dry_run_flag(opts)
|
56
57
|
add_error_on_annotation_flag(opts)
|
58
|
+
add_controllers_pattern_flag(opts)
|
57
59
|
add_verbose_flag(opts)
|
58
60
|
add_version_flag(opts)
|
59
61
|
add_help_flag(opts)
|
@@ -80,6 +82,16 @@ module Chusaku
|
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
85
|
+
# Adds `--controllers-pattern` flag.
|
86
|
+
#
|
87
|
+
# @param opts [OptionParser] OptionParser instance
|
88
|
+
# @return [void]
|
89
|
+
def add_controllers_pattern_flag(opts)
|
90
|
+
opts.on("-c", "--controllers-pattern", "=GLOB", "Specify alternative controller files glob pattern") do |value|
|
91
|
+
@options[:controllers_pattern] = value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
83
95
|
# Adds `--verbose` flag.
|
84
96
|
#
|
85
97
|
# @param opts [OptionParser] OptionParser instance
|
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
data/lib/chusaku.rb
CHANGED
@@ -20,7 +20,7 @@ module Chusaku
|
|
20
20
|
@routes = Chusaku::Routes.call
|
21
21
|
@changes = []
|
22
22
|
@changed_files = []
|
23
|
-
controllers_pattern = "app/controllers/**/*_controller.rb"
|
23
|
+
controllers_pattern = @flags[:controllers_pattern] || "app/controllers/**/*_controller.rb"
|
24
24
|
|
25
25
|
Dir.glob(Rails.root.join(controllers_pattern)).each do |path|
|
26
26
|
controller = %r{controllers/(.*)_controller\.rb}.match(path)[1]
|
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:
|
4
|
+
version: 1.1.0
|
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-09-03 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.19
|
132
|
+
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Annotate your Rails controllers with route info.
|
135
135
|
test_files: []
|