chusaku 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +2 -2
- data/.github/workflows/testing.yml +2 -2
- data/.gitignore +1 -0
- data/README.md +28 -16
- data/lib/chusaku/cli.rb +1 -1
- data/lib/chusaku/version.rb +1 -1
- data/lib/chusaku.rb +16 -50
- data/lib/tasks/chusaku.rake +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73db691fb40f399f999f495736dca02bd8c372934aa4122824d086a723d0479
|
4
|
+
data.tar.gz: dea436d47f3101f5d3112c3722b04c00b317fc32c7ad3ee2c2594ca12fbe3c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03bff26c3f0a2de5ed0b4c64feb3c2a198c4704f53f3683d5bbcf0699f2c36081672324ea871ed664836d0a6d09f9314b1b4c23d886885597c7e9f03bcb13821
|
7
|
+
data.tar.gz: 8d4def4efa795ac278608c7d9c8f19dd361e361b4e1ff4da7a9434fa85d865acb3de28e183d67f74bf244023220ad84464735da275516a236576c29dde9d9d64
|
@@ -6,9 +6,9 @@ jobs:
|
|
6
6
|
steps:
|
7
7
|
- uses: actions/checkout@v2
|
8
8
|
- name: Set up Ruby
|
9
|
-
uses: ruby/setup-ruby@
|
9
|
+
uses: ruby/setup-ruby@v1
|
10
10
|
with:
|
11
|
-
ruby-version: 3.
|
11
|
+
ruby-version: 3.3
|
12
12
|
bundler-cache: true
|
13
13
|
- name: Run Standard
|
14
14
|
run: bundle exec standardrb --fail-level A
|
@@ -5,11 +5,11 @@ jobs:
|
|
5
5
|
runs-on: ubuntu-latest
|
6
6
|
strategy:
|
7
7
|
matrix:
|
8
|
-
ruby-version: ["
|
8
|
+
ruby-version: ["3.1", "3.2", "3.3"]
|
9
9
|
steps:
|
10
10
|
- uses: actions/checkout@v2
|
11
11
|
- name: Set up Ruby
|
12
|
-
uses: ruby/setup-ruby@
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
13
|
with:
|
14
14
|
ruby-version: ${{ matrix.ruby-version }}
|
15
15
|
bundler-cache: true
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -26,16 +26,14 @@ Add this line to your Rails application's Gemfile:
|
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
group :development do
|
29
|
-
# ...
|
30
29
|
gem "chusaku", require: false
|
31
|
-
# ...
|
32
30
|
end
|
33
31
|
```
|
34
32
|
|
35
33
|
And then execute:
|
36
34
|
|
37
|
-
```
|
38
|
-
|
35
|
+
```sh
|
36
|
+
bundle install
|
39
37
|
```
|
40
38
|
|
41
39
|
|
@@ -43,8 +41,8 @@ $ bundle install
|
|
43
41
|
|
44
42
|
From the root of your Rails application, run:
|
45
43
|
|
46
|
-
```
|
47
|
-
|
44
|
+
```sh
|
45
|
+
bundle exec chusaku
|
48
46
|
```
|
49
47
|
|
50
48
|
Chusaku has some flags available for use as well:
|
@@ -55,23 +53,37 @@ Usage: chusaku [options]
|
|
55
53
|
--dry-run Run without file modifications
|
56
54
|
--exit-with-error-on-annotation Fail if any file was annotated
|
57
55
|
-c, --controllers-pattern=GLOB Specify alternative controller files glob pattern
|
58
|
-
--verbose Print all
|
56
|
+
--verbose Print all annotated files
|
59
57
|
-v, --version Show Chusaku version number and quit
|
60
58
|
-h, --help Show this help message and quit
|
59
|
+
```
|
60
|
+
|
61
|
+
### Rake usage
|
62
|
+
|
63
|
+
If you'd like to use Chusaku as a Rake task, add the following line to your `Rakefile`:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require "chusaku"
|
67
|
+
Chusaku.load_tasks
|
68
|
+
```
|
69
|
+
|
70
|
+
This will then allow you to call:
|
71
|
+
|
72
|
+
```sh
|
73
|
+
bin/rake chusaku
|
74
|
+
```
|
75
|
+
|
76
|
+
To pass flags, pass them like you would from the CLI executable:
|
61
77
|
|
78
|
+
```sh
|
79
|
+
bin/rake chusaku -- --dry-run --exit-with-error-on-annotation
|
62
80
|
```
|
63
81
|
|
64
82
|
|
65
83
|
## Development
|
66
84
|
|
67
|
-
Read the blog post explaining how the gem works at a high level:
|
68
|
-
https://nshki.com/chusaku-a-controller-annotation-gem.
|
85
|
+
Read the blog post explaining how the gem works at a high level: https://nshki.com/chusaku-a-controller-annotation-gem.
|
69
86
|
|
70
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
71
|
-
`bundle exec rake test` to run the tests. You can also run `bin/console` for an
|
72
|
-
interactive prompt that will allow you to experiment.
|
87
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
88
|
|
74
|
-
To release a new version, update the version number in `version.rb`, and then
|
75
|
-
run `bundle exec rake release`, which will create a git tag for the version,
|
76
|
-
git commits and tags, and push the `.gem` file to
|
77
|
-
[rubygems.org](https://rubygems.org).
|
89
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/lib/chusaku/cli.rb
CHANGED
@@ -97,7 +97,7 @@ module Chusaku
|
|
97
97
|
# @param opts [OptionParser] OptionParser instance
|
98
98
|
# @return [void]
|
99
99
|
def add_verbose_flag(opts)
|
100
|
-
opts.on("--verbose", "Print all
|
100
|
+
opts.on("--verbose", "Print all annotated files") do
|
101
101
|
@options[:verbose] = true
|
102
102
|
end
|
103
103
|
end
|
data/lib/chusaku/version.rb
CHANGED
data/lib/chusaku.rb
CHANGED
@@ -18,7 +18,6 @@ module Chusaku
|
|
18
18
|
def call(flags = {})
|
19
19
|
@flags = flags
|
20
20
|
@routes = Chusaku::Routes.call
|
21
|
-
@changes = []
|
22
21
|
@changed_files = []
|
23
22
|
controllers_pattern = @flags[:controllers_pattern] || "app/controllers/**/*_controller.rb"
|
24
23
|
|
@@ -33,6 +32,15 @@ module Chusaku
|
|
33
32
|
output_results
|
34
33
|
end
|
35
34
|
|
35
|
+
# Load Rake tasks for Chusaku. Should be called in your project's `Rakefile`.
|
36
|
+
#
|
37
|
+
# @return [void]
|
38
|
+
def load_tasks
|
39
|
+
Dir[File.join(File.dirname(__FILE__), "tasks", "**/*.rake")].each do |task|
|
40
|
+
load(task)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
private
|
37
45
|
|
38
46
|
# Adds annotations to the given file.
|
@@ -44,46 +52,18 @@ module Chusaku
|
|
44
52
|
def annotate_file(path:, controller:, actions:)
|
45
53
|
parsed_file = Chusaku::Parser.call(path: path, actions: actions)
|
46
54
|
parsed_file[:groups].each_cons(2) do |prev, curr|
|
47
|
-
|
55
|
+
clean_group(prev)
|
48
56
|
next unless curr[:type] == :action
|
49
57
|
|
50
58
|
route_data = @routes[controller][curr[:action]]
|
51
59
|
next unless route_data.any?
|
52
60
|
|
53
|
-
|
61
|
+
annotate_group(group: curr, route_data: route_data)
|
54
62
|
end
|
55
63
|
|
56
64
|
write_to_file(path: path, parsed_file: parsed_file)
|
57
65
|
end
|
58
66
|
|
59
|
-
# Clean or annotate a group and track the group as changed if applicable.
|
60
|
-
#
|
61
|
-
# @param group [Hash] { type => Symbol, body => String }
|
62
|
-
# @param type [Symbol] [:clean, :annotate]
|
63
|
-
# @param path [String] File path
|
64
|
-
# @param route_data [Array<Hash>] [{
|
65
|
-
# verb: String,
|
66
|
-
# path: String,
|
67
|
-
# name: String }]
|
68
|
-
# @return [void]
|
69
|
-
def record_change(group:, type:, path:, route_data: [])
|
70
|
-
old_body = group[:body]
|
71
|
-
|
72
|
-
case type
|
73
|
-
when :clean
|
74
|
-
clean_group(group)
|
75
|
-
when :annotate
|
76
|
-
annotate_group(group: group, route_data: route_data)
|
77
|
-
end
|
78
|
-
return if old_body == group[:body]
|
79
|
-
|
80
|
-
@changes.push \
|
81
|
-
old_body: old_body,
|
82
|
-
new_body: group[:body],
|
83
|
-
path: path,
|
84
|
-
line_number: group[:line_number]
|
85
|
-
end
|
86
|
-
|
87
67
|
# Given a parsed group, clean out its contents.
|
88
68
|
#
|
89
69
|
# @param group [Hash] { type => Symbol, body => String }
|
@@ -191,36 +171,22 @@ module Chusaku
|
|
191
171
|
#
|
192
172
|
# @return [String] Copy to be outputted to user
|
193
173
|
def output_copy
|
194
|
-
return "
|
174
|
+
return "Controller files unchanged." if @changed_files.empty?
|
195
175
|
|
196
176
|
copy = changes_copy
|
197
|
-
copy += "
|
177
|
+
copy += "Chusaku has finished running."
|
198
178
|
copy += "\nThis was a dry run so no files were changed." if @flags.include?(:dry)
|
199
179
|
copy += "\nExited with status code 1." if @flags.include?(:error_on_annotation)
|
200
180
|
copy
|
201
181
|
end
|
202
182
|
|
203
|
-
# Returns the copy for
|
183
|
+
# Returns the copy for changed files if `--verbose` flag is passed.
|
204
184
|
#
|
205
|
-
# @return [String] Copy
|
185
|
+
# @return [String] Copy for changed files
|
206
186
|
def changes_copy
|
207
187
|
return "" unless @flags.include?(:verbose)
|
208
188
|
|
209
|
-
@
|
210
|
-
<<~CHANGE_OUTPUT
|
211
|
-
[#{change[:path]}:#{change[:line_number]}]
|
212
|
-
|
213
|
-
Before:
|
214
|
-
```ruby
|
215
|
-
#{change[:old_body].chomp}
|
216
|
-
```
|
217
|
-
|
218
|
-
After:
|
219
|
-
```ruby
|
220
|
-
#{change[:new_body].chomp}
|
221
|
-
```
|
222
|
-
CHANGE_OUTPUT
|
223
|
-
end.join("\n")
|
189
|
+
@changed_files.map { |file| "Annotated #{file}" }.join("\n") + "\n"
|
224
190
|
end
|
225
191
|
end
|
226
192
|
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: 1.
|
4
|
+
version: 1.2.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:
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/chusaku/parser.rb
|
106
106
|
- lib/chusaku/routes.rb
|
107
107
|
- lib/chusaku/version.rb
|
108
|
+
- lib/tasks/chusaku.rake
|
108
109
|
homepage: https://github.com/nshki/chusaku
|
109
110
|
licenses:
|
110
111
|
- MIT
|
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.5.1
|
132
133
|
signing_key:
|
133
134
|
specification_version: 4
|
134
135
|
summary: Annotate your Rails controllers with route info.
|