chusaku 1.0.0 → 1.1.0

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: fcb89484056aea5e8df6216ee630a385e433aa1fe8e375f76dc1b9ec67a03792
4
- data.tar.gz: 377a1e400e828cd026a8dd75c2f1b592af71ce5a53c35d868fa3b173bc5357ba
3
+ metadata.gz: 62bb838dd76c648a120303c3a0bde8c67ea7232f90accb9f3e739a3b69764026
4
+ data.tar.gz: 9af1726825550cb4ce7d642e6a80217b8810cb6a56e8703c6d7f4f23a8643f3a
5
5
  SHA512:
6
- metadata.gz: 4656041fd2672f6c1c9c5c641d8489a0744b9de679971553d4c99a12934a97ad269264e34001801b10e22773bc8e5589c45225a46f55c239030b8d2b999fc416
7
- data.tar.gz: f97fd735b824e51cf45ab1e33fd6e2862e6c53530e52cacd23b400087759bece2210111493190f36c60ef2bf673055d58fbd5a66c4dc6a69922638416f40cf14
6
+ metadata.gz: 0baeb0a41404f911ef11b3d12709773a44ecc18aa542f5dcb854e1b67023b7fd79f640d10d7d8a4368121a33714327c5120ed701c9a67c238537023db78603e7
7
+ data.tar.gz: 1e5026ac8d35af5ff8c5d8c02d32d7d634716966dad3a61947398ee870203795ff91286bb43b7daf6802c4bace3df42b1ffb325c130e88b1fe26495d72100118
data/README.md CHANGED
@@ -52,12 +52,13 @@ 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 Run without file modifications
56
- --exit-with-error-on-annotation
57
- Fail if any file was annotated
58
- --verbose Print all annotations
59
- -v, --version Show Chusaku version number and quit
60
- -h, --help Show this help message and quit
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
61
+
61
62
  ```
62
63
 
63
64
 
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
@@ -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]] ||= datum[:name]
105
- datum[:name] ||= paths[datum[:path]]
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
@@ -1,3 +1,3 @@
1
1
  module Chusaku
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nishiki Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-28 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.4.17
131
+ rubygems_version: 3.4.19
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Annotate your Rails controllers with route info.