awesome_annotate 0.1.3 → 0.1.5

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: 14fd05f02d2e589431ee8ca8b52911aa1365e2daebcb835e78b9cbfaf2198e69
4
- data.tar.gz: 8a5de3f58b1c8f0cb94a8737b9ca01c9988868c8a797c8382f53dd6cf060cb8c
3
+ metadata.gz: add6a26de84b0dab25e21c0c60213a8d0c6aef0109a552faf635fdfb745e5bcb
4
+ data.tar.gz: 6a9494f2aeafe2e163c59f1544f181da0d39aef6736851412580c1b59231631a
5
5
  SHA512:
6
- metadata.gz: 7584be12529764fc8a172dd29672331842eb2cb00371bafad1691c67206386452ccc8a8e28c42e0f55bca49522a5b944cd1b56cc55c74cb608c60ec194dba6ca
7
- data.tar.gz: 51d1c40aeba22f1f941da7539e6ee489dbce49d60b7af457ea08650e933a36c276943b522fd58c412caced26699b547aefdfea68d0747b6e56886811898ada76
6
+ metadata.gz: 9654317d619c0d5e4706b1a5fb1f6899a123a3f8b6acb79c29d744d65ed5c6d1a895e9cbd835653e1d33de80055c75a24e0f38fd365d2e58112738cf2e70b763
7
+ data.tar.gz: 807524f834b4087643d8fc2e2477ebd271f6eac9a989d947b9ac3dd693259baf7890187e3201293d4e809f6dfef9f7abe05542f3a287e17af0a527d54d955acc
data/.rspec_status ADDED
@@ -0,0 +1,11 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/awesome_annotate_spec.rb[1:1] | passed | 0.00031 seconds |
4
+ ./spec/lib/awesome_annotate/cli_spec.rb[1:3:1] | passed | 0.00185 seconds |
5
+ ./spec/lib/awesome_annotate/model_spec.rb[1:1:1:1:1] | passed | 0.19755 seconds |
6
+ ./spec/lib/awesome_annotate/model_spec.rb[1:1:1:2:1] | passed | 0.00078 seconds |
7
+ ./spec/lib/awesome_annotate/model_spec.rb[1:1:1:3:1] | passed | 0.00018 seconds |
8
+ ./spec/lib/awesome_annotate/model_spec.rb[1:1:2:1] | passed | 0.00008 seconds |
9
+ ./spec/lib/awesome_annotate/route_spec.rb[1:1:1:1:1] | passed | 0.00303 seconds |
10
+ ./spec/lib/awesome_annotate/route_spec.rb[1:1:1:2:1] | passed | 0.0005 seconds |
11
+ ./spec/lib/awesome_annotate/route_spec.rb[1:1:2:1] | passed | 0.00009 seconds |
@@ -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
@@ -14,12 +14,14 @@ module AwesomeAnnotate
14
14
  say AwesomeAnnotate::VERSION
15
15
  end
16
16
 
17
+ map %w[model -m] => :model
17
18
  desc 'model [model_name]', 'annotate your model'
18
19
  def model(model_name)
19
20
  AwesomeAnnotate::Model.new.annotate(model_name)
20
21
  end
21
22
 
22
- desc 'routes', 'annotate your route'
23
+ map %w[routes -r] => :routes
24
+ desc 'routes', "Writes application route information to `config/routes.rb`."
23
25
  def routes
24
26
  AwesomeAnnotate::Route.new.annotate
25
27
  end
@@ -0,0 +1,2 @@
1
+
2
+ class NotFoundError < StandardError; end
@@ -1,15 +1,22 @@
1
1
  require 'active_record'
2
2
  require 'thor'
3
+ require_relative 'error'
3
4
 
4
5
  module AwesomeAnnotate
5
6
  class Model < Thor
6
7
  include Thor::Actions
7
8
 
9
+ def initialize(params = {})
10
+ super()
11
+ @env_file_path = Pathname.new(params[:env_file_path] || 'config/environment.rb')
12
+ @model_dir = Pathname.new(params[:model_dir] || 'app/models')
13
+ end
14
+
8
15
  desc 'model [model name]', 'annotate your model'
9
16
  def annotate(model_name)
10
- abort "Rails application path is required" unless env_file_path.exist?
17
+ raise "Rails application path is required" unless @env_file_path.exist?
11
18
 
12
- apply env_file_path.to_s
19
+ apply @env_file_path.to_s
13
20
 
14
21
  klass = klass_name(model_name)
15
22
 
@@ -25,16 +32,12 @@ module AwesomeAnnotate
25
32
 
26
33
  private
27
34
 
28
- def env_file_path
29
- Pathname.new('config/environment.rb')
30
- end
31
-
32
35
  def model_dir
33
36
  Pathname.new('app/models')
34
37
  end
35
38
 
36
39
  def insert_file_before_class(file_path, klass, message)
37
- insert_into_file file_path, :before => / class #{klass} \n|class #{klass} .*\n / do
40
+ insert_into_file file_path, :before => /^class\s+\w+\s+<\s+\w+/ do
38
41
  message
39
42
  end
40
43
  end
@@ -44,10 +47,11 @@ module AwesomeAnnotate
44
47
  end
45
48
 
46
49
  def model_file_path(model_name)
47
- file_path = "#{model_dir}/#{model_name}.rb"
50
+ file_path = "#{@model_dir}/#{model_name}.rb"
48
51
 
49
52
  unless File.exist?(file_path)
50
- return say "Model file not found"
53
+ say "Model file not found"
54
+ raise NotFoundError
51
55
  end
52
56
 
53
57
  return file_path
@@ -55,10 +59,11 @@ module AwesomeAnnotate
55
59
 
56
60
  def klass_name(model_name)
57
61
  name = model_name.singularize.camelize
58
- klass = Object.const_get(name)
62
+ return Object.const_get(name)
59
63
 
60
64
  rescue NameError
61
65
  say "Model not found"
66
+ raise NotFoundError
62
67
  end
63
68
 
64
69
  def self.source_root
@@ -5,11 +5,17 @@ module AwesomeAnnotate
5
5
  class Route < Thor
6
6
  include Thor::Actions
7
7
 
8
+ def initialize(params = {})
9
+ super()
10
+ @env_file_path = Pathname.new(params[:env_file_path] || 'config/environment.rb')
11
+ @route_file_path = Pathname.new(params[:route_file_path] || 'config/routes.rb')
12
+ end
13
+
8
14
  desc 'annotate all routes', 'annotate your routes'
9
15
  def annotate
10
- abort "Rails application path is required" unless env_file_path.exist?
16
+ raise "Rails application path is required" unless @env_file_path.exist?
11
17
 
12
- apply env_file_path.to_s
18
+ apply @env_file_path.to_s
13
19
 
14
20
  inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
15
21
  formatter = ActionDispatch::Routing::ConsoleFormatter::Sheet.new
@@ -17,20 +23,14 @@ module AwesomeAnnotate
17
23
  routes = inspector.format(formatter, {})
18
24
  route_message = parse_routes(routes)
19
25
 
20
- insert_file_before_class(route_file_path, route_message)
26
+ raise "Route file not found" unless @route_file_path.exist?
21
27
 
22
- say "annotate routes in #{route_file_path}"
23
- end
28
+ insert_file_before_class(@route_file_path, route_message)
24
29
 
25
- private
26
-
27
- def env_file_path
28
- Pathname.new('config/environment.rb')
30
+ say "annotate routes in #{@route_file_path}"
29
31
  end
30
32
 
31
- def route_file_path
32
- Pathname.new('config/routes.rb')
33
- end
33
+ private
34
34
 
35
35
  def parse_routes(routes)
36
36
  split_routes = routes.split(/\r\n|\r|\n/)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeAnnotate
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
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.3
4
+ version: 0.1.5
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-07 00:00:00.000000000 Z
11
+ date: 2024-09-03 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
@@ -47,6 +47,7 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - ".rspec"
50
+ - ".rspec_status"
50
51
  - ".rubocop.yml"
51
52
  - CHANGELOG.md
52
53
  - LICENSE.txt
@@ -56,6 +57,7 @@ files:
56
57
  - exe/awesome_annotate
57
58
  - lib/awesome_annotate.rb
58
59
  - lib/awesome_annotate/cli.rb
60
+ - lib/awesome_annotate/error.rb
59
61
  - lib/awesome_annotate/model.rb
60
62
  - lib/awesome_annotate/route.rb
61
63
  - lib/awesome_annotate/version.rb