Skip to content

Commit 5320459

Browse files
authored
Make annotaterb usable (#11)
Tons of changes to make the gem usable after the refactors. Notable changes in behavior: * The CLI options and format * Removal of rake tasks that get added to Rails app when running `bin/rails generate annotate_rb:install`
1 parent caa1ae7 commit 5320459

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+672
-669
lines changed

.annotaterb.yml

Whitespace-only changes.

dummyapp/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
2424
# Reduces boot times through caching; required in config/boot.rb
2525
gem "bootsnap", require: false
2626

27+
gem 'pry'
28+
gem 'pry-byebug'
29+
2730
group :development, :test do
2831
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
2932
gem "debug", platforms: %i[ mri mingw x64_mingw ]

dummyapp/Gemfile.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ GEM
7575
bootsnap (1.16.0)
7676
msgpack (~> 1.2)
7777
builder (3.2.4)
78+
byebug (11.1.3)
79+
coderay (1.1.3)
7880
concurrent-ruby (1.2.0)
7981
crass (1.0.6)
8082
date (3.3.3)
@@ -114,6 +116,12 @@ GEM
114116
nio4r (2.5.8)
115117
nokogiri (1.14.1-arm64-darwin)
116118
racc (~> 1.4)
119+
pry (0.14.2)
120+
coderay (~> 1.1)
121+
method_source (~> 1.0)
122+
pry-byebug (3.10.1)
123+
byebug (~> 11.0)
124+
pry (>= 0.13, < 0.15)
117125
puma (5.6.5)
118126
nio4r (~> 2.0)
119127
racc (1.6.2)
@@ -171,6 +179,8 @@ DEPENDENCIES
171179
annotaterb!
172180
bootsnap
173181
debug
182+
pry
183+
pry-byebug
174184
puma (~> 5.0)
175185
rails (~> 7.0.4, >= 7.0.4.2)
176186
sqlite3 (~> 1.4)

exe/annotate

Lines changed: 0 additions & 34 deletions
This file was deleted.

exe/annotaterb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4+
unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
5+
abort 'Please run annotaterb from the root of the project.'
6+
end
7+
8+
begin
9+
require 'bundler'
10+
Bundler.setup
11+
rescue StandardError
12+
end
13+
414
$LOAD_PATH.unshift("#{__dir__}/../lib")
515

616
require 'annotate_rb'
717

8-
cli = AnnotateRb::CLI.new
9-
exit_status = cli.run
18+
exit_status = ::AnnotateRb::Runner.run(ARGV)
1019

11-
exit exit_status
20+
# TODO: Return exit status
21+
# exit exit_status

lib/annotate_rb.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
# frozen_string_literal: true
22

3+
require 'active_record'
4+
require 'active_support'
5+
6+
# Helper.fallback depends on this being required because it adds #present? to nil
7+
require 'active_support/core_ext/object/blank'
8+
require 'active_support/core_ext/class/subclasses'
9+
require 'active_support/core_ext/string/inflections'
10+
11+
require 'rake'
12+
13+
require 'annotate_rb/active_record_patch'
14+
315
require_relative 'annotate_rb/core'
16+
require_relative 'annotate_rb/commands'
417
require_relative 'annotate_rb/parser'
5-
require_relative 'annotate_rb/cli'
618
require_relative 'annotate_rb/runner'
7-
require_relative 'annotate_rb/commands'
819
require_relative 'annotate_rb/route_annotator'
920
require_relative 'annotate_rb/model_annotator'
10-
require_relative 'annotate_rb/old_annotate'
1121
require_relative 'annotate_rb/env'
1222
require_relative 'annotate_rb/options'
23+
require_relative 'annotate_rb/eager_loader'
24+
require_relative 'annotate_rb/rake_bootstrapper'
25+
require_relative 'annotate_rb/config_finder'
26+
require_relative 'annotate_rb/config_loader'
1327

1428
module AnnotateRb
1529

lib/annotate_rb/cli.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/annotate_rb/commands.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
module AnnotateRb
44
module Commands
5-
autoload :Help, 'annotate_rb/commands/help'
6-
autoload :Version, 'annotate_rb/commands/version'
5+
autoload :PrintVersion, 'annotate_rb/commands/print_version'
6+
autoload :PrintHelp, 'annotate_rb/commands/print_help'
7+
autoload :AnnotateModels, 'annotate_rb/commands/annotate_models'
8+
autoload :AnnotateRoutes, 'annotate_rb/commands/annotate_routes'
79
end
810
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module AnnotateRb
4+
module Commands
5+
class AnnotateModels
6+
def call(options)
7+
puts "Annotating models"
8+
9+
if options[:debug]
10+
puts "Running with debug mode, options:"
11+
pp options.to_h
12+
end
13+
14+
# Eager load Models when we're annotating models
15+
AnnotateRb::EagerLoader.call(options)
16+
17+
AnnotateRb::ModelAnnotator::Annotator.send(options[:target_action], options)
18+
end
19+
end
20+
end
21+
end
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module AnnotateRb
4+
module Commands
5+
class AnnotateRoutes
6+
def call(options)
7+
puts "Annotating routes"
8+
9+
if options[:debug]
10+
puts "Running with debug mode, options:"
11+
pp options.to_h
12+
end
13+
14+
AnnotateRb::RouteAnnotator::Annotator.send(options[:target_action], options)
15+
end
16+
end
17+
end
18+
end
19+

0 commit comments

Comments
 (0)