Skip to content

Commit 00c56dd

Browse files
authored
More work (#6)
1 parent bd03f5d commit 00c56dd

File tree

64 files changed

+4296
-1898
lines changed

Some content is hidden

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

64 files changed

+4296
-1898
lines changed

Gemfile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@ source 'https://rubygems.org'
22
gemspec
33

44
gem 'activerecord', require: false
5-
gem 'rake', require: false
6-
7-
group :development do
8-
platforms :mri, :mingw do
9-
gem 'yard', require: false
10-
end
11-
end
5+
gem 'rake'
6+
gem 'rspec'
127

138
group :development, :test do
149
gem 'byebug'
1510
gem 'guard-rspec', require: false
16-
gem 'rspec', require: false
1711

18-
gem 'rubocop', '~> 1.12.0', require: false
19-
gem 'rubocop-rake', require: false
20-
gem 'rubocop-rspec', '~> 2.2.0', require: false
2112
gem 'terminal-notifier-guard', require: false
2213

2314
gem 'overcommit'
@@ -29,6 +20,6 @@ group :development, :test do
2920
end
3021

3122
group :test do
32-
gem 'files', require: false
23+
gem 'files', require: false, path: "vendor/files"
3324
gem 'git', require: false
3425
end

annotaterb.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
1919
spec.metadata["changelog_uri"] = "https://github.com/drwl/annotaterb/blob/master/CHANGELOG.md"
2020
spec.metadata["bug_tracker_uri"] = "https://github.com/drwl/annotaterb/issues"
2121

22-
spec.files = Dir["VERSION", "CHANGELOG.md", "LICENSE.txt", "README.md", "lib/**/*", "bin/**/*"]
22+
spec.files = Dir["VERSION", "CHANGELOG.md", "LICENSE.txt", "README.md", "lib/**/*"]
2323
spec.bindir = "exe"
2424
spec.executables = Dir["exe/*"].map { |exe| File.basename(exe) }
2525
spec.require_paths = ["lib"]

bin/console

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "annotate_rb"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require "irb"
15+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

bin/annotate renamed to exe/annotate

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ require 'annotate/parser'
1919

2020
Annotate.bootstrap_rake
2121

22+
# Annotate::Parser.parse takes in ARGV
23+
# - Parses it and writes stuff to ENV
24+
# - Returns some in a hash as seen below, this script will exit if `:exit` is defined
2225
options_result = Annotate::Parser.parse(ARGV)
2326

2427
exit if options_result[:exit]
2528

29+
# Not sure what this does yet
2630
options = Annotate.setup_options(
31+
# .setup_options takes in starting options. It looks like :is_rake is used later down the road so we want to capture
32+
# if it was done via rake task or not.
33+
#
34+
# Looks like it's set in lib/tasks/annotate*.rake files
2735
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
2836
)
37+
38+
# Eager load Models when we're annotating models
2939
Annotate.eager_load(options) if Annotate::Helpers.include_models?
3040

41+
# options_result[:target_action] has possible values of: [:do_annotations, :remove_annotations]
3142
AnnotateModels.send(options_result[:target_action], options) if Annotate::Helpers.include_models?
3243
AnnotateRoutes.send(options_result[:target_action], options) if Annotate::Helpers.include_routes?

exe/annotaterb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
$LOAD_PATH.unshift("#{__dir__}/../lib")
5+
6+
require 'annotate_rb'
7+
8+
cli = AnnotateRb::CLI.new
9+
exit_status = cli.run
10+
11+
exit exit_status

lib/annotate.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ def self.setup_options(options = {})
7171
options
7272
end
7373

74+
# Can be used by consumers, per README:
75+
#
76+
# To automatically annotate every time you run `db:migrate`,
77+
# either run `rails g annotate:install`
78+
# or add `Annotate.load_tasks` to your `Rakefile`.
7479
def self.load_tasks
7580
return if @tasks_loaded
7681

82+
# Loads rake tasks, not sure why yet
7783
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each do |rake|
7884
load rake
7985
end
@@ -86,17 +92,8 @@ def self.eager_load(options)
8692
require 'annotate/active_record_patch'
8793

8894
if defined?(Rails::Application)
89-
if Rails.version.split('.').first.to_i < 3
90-
Rails.configuration.eager_load_paths.each do |load_path|
91-
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
92-
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
93-
require_dependency file.sub(matcher, '\1')
94-
end
95-
end
96-
else
97-
klass = Rails::Application.send(:subclasses).first
98-
klass.eager_load!
99-
end
95+
klass = Rails::Application.send(:subclasses).first
96+
klass.eager_load!
10097
else
10198
options[:model_dir].each do |dir|
10299
FileList["#{dir}/**/*.rb"].each do |fname|
@@ -131,6 +128,11 @@ def self.bootstrap_rake
131128
end
132129

133130
load_tasks
131+
132+
# This line loads the defaults option values for Annotate
133+
# Then "writes" them to ENV if a value for them doesn't already exist
134+
#
135+
# Calls: .set_defaults
134136
Rake::Task[:set_annotation_options].invoke
135137
end
136138

0 commit comments

Comments
 (0)