awesome_annotate 0.1.2 → 0.1.3

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: b32b0b966e78664837bbf66e85c75e882f6f6ecaff193b7ba0e0d1ce7fae42bc
4
- data.tar.gz: d1293087a0c3f44ff72aa9ff4cd6ad02effa90afd8562160c68dbc1267353edb
3
+ metadata.gz: 14fd05f02d2e589431ee8ca8b52911aa1365e2daebcb835e78b9cbfaf2198e69
4
+ data.tar.gz: 8a5de3f58b1c8f0cb94a8737b9ca01c9988868c8a797c8382f53dd6cf060cb8c
5
5
  SHA512:
6
- metadata.gz: 28d077b539bcef973f6576576084c809f090f132401cdd8ca0f36eeebe7fd7d4d99d68cd1b7412c470e658f2e80a56959ff886c8543283758ef44ec8296a94c2
7
- data.tar.gz: 1a18894e57ef95c194fe94b2c0aedaa5ad183ed64251857328875a274ca23bb76aa7e1419578c6d00b52e3f7e65b5b608d40bd85a6287cea125b909029bb95d8
6
+ metadata.gz: 7584be12529764fc8a172dd29672331842eb2cb00371bafad1691c67206386452ccc8a8e28c42e0f55bca49522a5b944cd1b56cc55c74cb608c60ec194dba6ca
7
+ data.tar.gz: 51d1c40aeba22f1f941da7539e6ee489dbce49d60b7af457ea08650e933a36c276943b522fd58c412caced26699b547aefdfea68d0747b6e56886811898ada76
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
@@ -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
@@ -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.3"
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.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-03 00:00:00.000000000 Z
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