awesome_annotate 0.1.4 → 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: 231c9ce46ab9f54c995580b73fc46b2f16df5531ab979b0fa9ce7273e34c5fda
4
- data.tar.gz: 0752a6de349b42c1658a8a907f503f1a16392a8d894af9436877c6cb83dbe68a
3
+ metadata.gz: add6a26de84b0dab25e21c0c60213a8d0c6aef0109a552faf635fdfb745e5bcb
4
+ data.tar.gz: 6a9494f2aeafe2e163c59f1544f181da0d39aef6736851412580c1b59231631a
5
5
  SHA512:
6
- metadata.gz: 37e53bcca2c79b97e551397f0dd6c92ab0c1f2b833edb05175100b0548c00c8b3117ea4aa528ef9f37e604329805f65f98ba9ac48c6bc2661b6395777de3028e
7
- data.tar.gz: c38e57f6d68825d3917fa0c9926be4ac7526c5a0154c568afc18b802363bd4af1e7e37e22581ea009a0fa5bdb1ab0f0d3c9f1f5f11f12e21dfc7ee3d89a2862a
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 |
@@ -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,10 +32,6 @@ 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
@@ -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.4"
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.4
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-06-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
@@ -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