awesome_annotate 0.1.2 → 0.1.3
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/CHANGELOG.md +11 -6
- data/lib/awesome_annotate/cli.rb +6 -0
- data/lib/awesome_annotate/route.rb +55 -0
- data/lib/awesome_annotate/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14fd05f02d2e589431ee8ca8b52911aa1365e2daebcb835e78b9cbfaf2198e69
|
4
|
+
data.tar.gz: 8a5de3f58b1c8f0cb94a8737b9ca01c9988868c8a797c8382f53dd6cf060cb8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7584be12529764fc8a172dd29672331842eb2cb00371bafad1691c67206386452ccc8a8e28c42e0f55bca49522a5b944cd1b56cc55c74cb608c60ec194dba6ca
|
7
|
+
data.tar.gz: 51d1c40aeba22f1f941da7539e6ee489dbce49d60b7af457ea08650e933a36c276943b522fd58c412caced26699b547aefdfea68d0747b6e56886811898ada76
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
## [0.1.
|
3
|
+
## [0.1.3] - 2024-05-05
|
4
4
|
|
5
|
-
-
|
5
|
+
- Add a new feature
|
6
|
+
- annotate routes command
|
7
|
+
|
8
|
+
## [0.1.2] - 2024-05-03
|
9
|
+
|
10
|
+
- Add a new feature
|
11
|
+
- --version flag
|
6
12
|
|
7
13
|
## [0.1.1] - 2024-05-02
|
8
14
|
|
9
15
|
- Fixed a bug
|
10
16
|
|
11
|
-
## [0.1.
|
17
|
+
## [0.1.0] - 2024-04-29
|
12
18
|
|
13
|
-
-
|
14
|
-
- --version flag
|
19
|
+
- Initial release
|
data/lib/awesome_annotate/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'awesome_annotate'
|
2
2
|
require 'awesome_annotate/model'
|
3
|
+
require 'awesome_annotate/route'
|
3
4
|
require 'awesome_annotate/version'
|
4
5
|
require 'thor'
|
5
6
|
|
@@ -18,6 +19,11 @@ module AwesomeAnnotate
|
|
18
19
|
AwesomeAnnotate::Model.new.annotate(model_name)
|
19
20
|
end
|
20
21
|
|
22
|
+
desc 'routes', 'annotate your route'
|
23
|
+
def routes
|
24
|
+
AwesomeAnnotate::Route.new.annotate
|
25
|
+
end
|
26
|
+
|
21
27
|
private
|
22
28
|
|
23
29
|
def self.exit_on_failure?
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module AwesomeAnnotate
|
5
|
+
class Route < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
desc 'annotate all routes', 'annotate your routes'
|
9
|
+
def annotate
|
10
|
+
abort "Rails application path is required" unless env_file_path.exist?
|
11
|
+
|
12
|
+
apply env_file_path.to_s
|
13
|
+
|
14
|
+
inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
|
15
|
+
formatter = ActionDispatch::Routing::ConsoleFormatter::Sheet.new
|
16
|
+
|
17
|
+
routes = inspector.format(formatter, {})
|
18
|
+
route_message = parse_routes(routes)
|
19
|
+
|
20
|
+
insert_file_before_class(route_file_path, route_message)
|
21
|
+
|
22
|
+
say "annotate routes in #{route_file_path}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def env_file_path
|
28
|
+
Pathname.new('config/environment.rb')
|
29
|
+
end
|
30
|
+
|
31
|
+
def route_file_path
|
32
|
+
Pathname.new('config/routes.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_routes(routes)
|
36
|
+
split_routes = routes.split(/\r\n|\r|\n/)
|
37
|
+
parse_routes = split_routes.map do |route|
|
38
|
+
"# #{route}\n"
|
39
|
+
end
|
40
|
+
parse_routes.push("\n")
|
41
|
+
parse_routes.unshift("#---This is route annotate---\n#\n")
|
42
|
+
parse_routes.join
|
43
|
+
end
|
44
|
+
|
45
|
+
def insert_file_before_class(file_path, message)
|
46
|
+
insert_into_file file_path, :before => "Rails.application.routes.draw do\n" do
|
47
|
+
message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.source_root
|
52
|
+
Dir.pwd
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_annotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wisdom-plus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/awesome_annotate.rb
|
58
58
|
- lib/awesome_annotate/cli.rb
|
59
59
|
- lib/awesome_annotate/model.rb
|
60
|
+
- lib/awesome_annotate/route.rb
|
60
61
|
- lib/awesome_annotate/version.rb
|
61
62
|
- sig/awesome_annotate.rbs
|
62
63
|
homepage: https://github.com/wisdom-plus/awesome_annotate
|