awesome_annotate 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -6
- data/awesome_annotate.gemspec +1 -7
- data/lib/awesome_annotate/cli.rb +8 -0
- data/lib/awesome_annotate/model.rb +1 -1
- data/lib/awesome_annotate/route.rb +55 -0
- data/lib/awesome_annotate/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231c9ce46ab9f54c995580b73fc46b2f16df5531ab979b0fa9ce7273e34c5fda
|
4
|
+
data.tar.gz: 0752a6de349b42c1658a8a907f503f1a16392a8d894af9436877c6cb83dbe68a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37e53bcca2c79b97e551397f0dd6c92ab0c1f2b833edb05175100b0548c00c8b3117ea4aa528ef9f37e604329805f65f98ba9ac48c6bc2661b6395777de3028e
|
7
|
+
data.tar.gz: c38e57f6d68825d3917fa0c9926be4ac7526c5a0154c568afc18b802363bd4af1e7e37e22581ea009a0fa5bdb1ab0f0d3c9f1f5f11f12e21dfc7ee3d89a2862a
|
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/awesome_annotate.gemspec
CHANGED
@@ -32,11 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
33
|
spec.require_paths = ["lib"]
|
34
34
|
spec.add_dependency "thor"
|
35
|
-
spec.add_dependency "activerecord", "
|
36
|
-
|
37
|
-
# Uncomment to register a new dependency of your gem
|
38
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
39
|
-
|
40
|
-
# For more information and examples about making a new gem, check out our
|
41
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
spec.add_dependency "activerecord", ">= 6.1.0"
|
42
36
|
end
|
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
|
|
@@ -13,11 +14,18 @@ module AwesomeAnnotate
|
|
13
14
|
say AwesomeAnnotate::VERSION
|
14
15
|
end
|
15
16
|
|
17
|
+
map %w[model -m] => :model
|
16
18
|
desc 'model [model_name]', 'annotate your model'
|
17
19
|
def model(model_name)
|
18
20
|
AwesomeAnnotate::Model.new.annotate(model_name)
|
19
21
|
end
|
20
22
|
|
23
|
+
map %w[routes -r] => :routes
|
24
|
+
desc 'routes', "Writes application route information to `config/routes.rb`."
|
25
|
+
def routes
|
26
|
+
AwesomeAnnotate::Route.new.annotate
|
27
|
+
end
|
28
|
+
|
21
29
|
private
|
22
30
|
|
23
31
|
def self.exit_on_failure?
|
@@ -34,7 +34,7 @@ module AwesomeAnnotate
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def insert_file_before_class(file_path, klass, message)
|
37
|
-
insert_into_file file_path, :before =>
|
37
|
+
insert_into_file file_path, :before => /^class\s+\w+\s+<\s+\w+/ do
|
38
38
|
message
|
39
39
|
end
|
40
40
|
end
|
@@ -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.4
|
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-
|
11
|
+
date: 2024-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 6.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 6.1.0
|
41
41
|
description: annotate your code with comments (e.g. model schema, routes, etc.)
|
42
42
|
email:
|
43
43
|
- wisdom.plus.264.dev@gmail.com
|
@@ -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
|