awesome_annotate 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b32b0b966e78664837bbf66e85c75e882f6f6ecaff193b7ba0e0d1ce7fae42bc
4
- data.tar.gz: d1293087a0c3f44ff72aa9ff4cd6ad02effa90afd8562160c68dbc1267353edb
3
+ metadata.gz: 231c9ce46ab9f54c995580b73fc46b2f16df5531ab979b0fa9ce7273e34c5fda
4
+ data.tar.gz: 0752a6de349b42c1658a8a907f503f1a16392a8d894af9436877c6cb83dbe68a
5
5
  SHA512:
6
- metadata.gz: 28d077b539bcef973f6576576084c809f090f132401cdd8ca0f36eeebe7fd7d4d99d68cd1b7412c470e658f2e80a56959ff886c8543283758ef44ec8296a94c2
7
- data.tar.gz: 1a18894e57ef95c194fe94b2c0aedaa5ad183ed64251857328875a274ca23bb76aa7e1419578c6d00b52e3f7e65b5b608d40bd85a6287cea125b909029bb95d8
6
+ metadata.gz: 37e53bcca2c79b97e551397f0dd6c92ab0c1f2b833edb05175100b0548c00c8b3117ea4aa528ef9f37e604329805f65f98ba9ac48c6bc2661b6395777de3028e
7
+ data.tar.gz: c38e57f6d68825d3917fa0c9926be4ac7526c5a0154c568afc18b802363bd4af1e7e37e22581ea009a0fa5bdb1ab0f0d3c9f1f5f11f12e21dfc7ee3d89a2862a
data/CHANGELOG.md CHANGED
@@ -1,14 +1,19 @@
1
- ## [Unreleased]
1
+ # Changelog
2
2
 
3
- ## [0.1.0] - 2024-04-29
3
+ ## [0.1.3] - 2024-05-05
4
4
 
5
- - Initial release
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.2] - 2024-05-03
17
+ ## [0.1.0] - 2024-04-29
12
18
 
13
- - Add a new feature
14
- - --version flag
19
+ - Initial release
@@ -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", "~> 7.1"
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
@@ -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 => / class #{klass} \n|class #{klass} .*\n / do
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeAnnotate
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  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.2
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-05-03 00:00:00.000000000 Z
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: '7.1'
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: '7.1'
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