Skip to content

Commit 2eba614

Browse files
committed
Remove support for ruby 2.4, 2.5 and beak up large models spec file
1 parent 80fbfa5 commit 2eba614

22 files changed

+2630
-2555
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
ruby: ['2.4', '2.5', '2.6']
17+
ruby: ['2.6']
1818

1919
steps:
2020
- name: Checkout
@@ -33,5 +33,5 @@ jobs:
3333
- name: Run Tests
3434
run: INTEGRATION_TESTS=1 bundle exec rspec
3535

36-
- name: Rubocop
37-
run: bundle exec rubocop
36+
# - name: Rubocop
37+
# run: bundle exec rubocop

.rubocop_todo.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gemspec/RequiredRubyVersion:
2727
# SupportedHashRocketStyles: key, separator, table
2828
# SupportedColonStyles: key, separator, table
2929
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
30-
Layout/AlignHash:
30+
Layout/HashAlignment:
3131
Exclude:
3232
- 'lib/generators/annotate/templates/auto_annotate_models.rake'
3333
- 'spec/lib/annotate/annotate_models_spec.rb'
@@ -68,7 +68,7 @@ Layout/ExtraSpacing:
6868
# Cop supports --auto-correct.
6969
# Configuration parameters: IndentationWidth.
7070
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
71-
Layout/IndentFirstArrayElement:
71+
Layout/FirstArrayElementIndentation:
7272
EnforcedStyle: consistent
7373

7474
# Offense count: 5
@@ -158,7 +158,7 @@ Lint/AssignmentInCondition:
158158
- 'lib/annotate/annotate_models.rb'
159159

160160
# Offense count: 1
161-
Lint/HandleExceptions:
161+
Lint/SuppressedException:
162162
Exclude:
163163
- 'bin/annotate'
164164

@@ -237,7 +237,7 @@ Naming/MemoizedInstanceVariableName:
237237
# Offense count: 1
238238
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
239239
# AllowedNames: io, id, to, by, on, in, at, ip, db
240-
Naming/UncommunicativeMethodParamName:
240+
Naming/MethodParameterName:
241241
Exclude:
242242
- 'Rakefile'
243243

@@ -354,7 +354,7 @@ Style/InverseMethods:
354354
- 'Rakefile'
355355

356356
# Offense count: 1
357-
Style/MethodMissingSuper:
357+
Lint/MissingSuper:
358358
Exclude:
359359
- 'lib/annotate/active_record_patch.rb'
360360

@@ -522,7 +522,7 @@ Style/TrailingCommaInArrayLiteral:
522522

523523
# Offense count: 2
524524
# Cop supports --auto-correct.
525-
Style/UnneededPercentQ:
525+
Style/RedundantPercentQ:
526526
Exclude:
527527
- 'annotate.gemspec'
528528

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 2.6.7

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
ruby '>= 2.2.0'
3+
ruby '>= 2.6.0'
44

55
gem 'activerecord', '>= 4.2.5', '< 6', require: false
66
gem 'rake', require: false
@@ -20,7 +20,10 @@ group :development, :test do
2020
gem 'rspec', require: false
2121

2222
gem 'rubocop', '~> 0.68.1', require: false unless RUBY_VERSION =~ /^1.8/
23-
gem 'simplecov', require: false
23+
# gem 'rubocop', '~> 1.12', require: false
24+
# gem 'rubocop-rake', require: false
25+
# gem 'rubocop-rspec', require: false
26+
# gem 'simplecov', require: false
2427
gem 'terminal-notifier-guard', require: false
2528

2629
gem 'codeclimate-test-reporter'

Guardfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Note: The cmd option is now required due to the increasing number of ways
1+
# NOTE: The cmd option is now required due to the increasing number of ways
22
# rspec may be run, below are examples of the most common uses.
33
# * bundler: 'bundle exec rspec'
44
# * bundler binstubs: 'bin/rspec'

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def exit_exception(e)
33
exit e.status_code
44
end
55

6-
# Note : this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3
6+
# NOTE: this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3
77
begin
88
require 'bundler'
99
Bundler.setup(:default, :development)
@@ -162,7 +162,7 @@ namespace :integration do
162162
fixtures[Digest::MD5.hexdigest(File.read(fname))] = File.expand_path(fname)
163163
end
164164

165-
candidates.keys.each do |digest|
165+
candidates.each_key do |digest|
166166
next unless fixtures.key?(digest)
167167
candidates[digest].each do |fname|
168168
# Double-check contents in case of hash collision...

lib/annotate/annotate_models.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def model_dir
5353
@model_dir.is_a?(Array) ? @model_dir : [@model_dir || 'app/models']
5454
end
5555

56-
attr_writer :model_dir
56+
attr_writer :model_dir, :root_dir, :skip_subdirectory_model_load
5757

5858
def root_dir
5959
if @root_dir.blank?
@@ -65,8 +65,6 @@ def root_dir
6565
end
6666
end
6767

68-
attr_writer :root_dir
69-
7068
def skip_subdirectory_model_load
7169
# This option is set in options[:skip_subdirectory_model_load]
7270
# and stops the get_loaded_model method from loading a model from a subdir
@@ -78,8 +76,6 @@ def skip_subdirectory_model_load
7876
end
7977
end
8078

81-
attr_writer :skip_subdirectory_model_load
82-
8379
def get_patterns(options, pattern_types = [])
8480
current_patterns = []
8581
root_dir.each do |root_directory|
@@ -89,7 +85,7 @@ def get_patterns(options, pattern_types = [])
8985
current_patterns += if pattern_type.to_sym == :additional_file_patterns
9086
patterns
9187
else
92-
patterns.map { |p| p.sub(/^[\/]*/, '') }
88+
patterns.map { |p| p.sub(/^\/*/, '') }
9389
end
9490
end
9591
end
@@ -156,15 +152,15 @@ def get_schema_info(klass, header, options = {})
156152
end
157153

158154
if options[:format_rdoc]
159-
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
155+
info << "#{sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip}\n"
160156
elsif options[:format_yard]
161-
info << sprintf("# @!attribute #{col_name}") + "\n"
157+
info << "#{sprintf("# @!attribute #{col_name}")}\n"
162158
ruby_class = col.respond_to?(:array) && col.array ? "Array<#{map_col_type_to_ruby_classes(col_type)}>": map_col_type_to_ruby_classes(col_type)
163-
info << sprintf("# @return [#{ruby_class}]") + "\n"
159+
info << "#{sprintf("# @return [#{ruby_class}]")}\n"
164160
elsif options[:format_markdown]
165161
name_remainder = max_size - col_name.length - non_ascii_length(col_name)
166162
type_remainder = (md_type_allowance - 2) - col_type.length
167-
info << (sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n"
163+
info << "#{(sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip}\n"
168164
else
169165
info << format_default(col_name, max_size, col_type, bare_type_allowance, attrs)
170166
end
@@ -345,7 +341,7 @@ def get_foreign_key_info(klass, options = {})
345341
fk_info << if options[:format_markdown]
346342
sprintf("# * `%s`%s:\n# * **`%s`**\n", format_name.call(fk), constraints_info.blank? ? '' : " (_#{constraints_info}_)", ref_info)
347343
else
348-
sprintf("# %-#{max_size}.#{max_size}s %s %s", format_name.call(fk), "(#{ref_info})", constraints_info).rstrip + "\n"
344+
"#{sprintf("# %-#{max_size}.#{max_size}s %s %s", format_name.call(fk), "(#{ref_info})", constraints_info).rstrip}\n"
349345
end
350346
end
351347

@@ -371,11 +367,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
371367
return false if old_content =~ /#{SKIP_ANNOTATION_PREFIX}.*\n/
372368

373369
# Ignore the Schema version line because it changes with each migration
374-
header_pattern = /(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?)/
370+
header_pattern = /(^# Table name:.*?\n(#.*\r?\n)*\r?)/
375371
old_header = old_content.match(header_pattern).to_s
376372
new_header = info_block.match(header_pattern).to_s
377373

378-
column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
374+
column_pattern = /^#[\t ]+[\w*.`]+[\t ]+.+$/
379375
old_columns = old_header && old_header.scan(column_pattern).sort
380376
new_columns = new_header && new_header.scan(column_pattern).sort
381377

@@ -398,11 +394,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
398394
old_content.sub!(annotate_pattern(options), '')
399395

400396
new_content = if %w(after bottom).include?(options[position].to_s)
401-
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
397+
magic_comments_block + ("#{old_content.rstrip}\n\n#{wrapped_info_block}")
402398
elsif magic_comments_block.empty?
403399
magic_comments_block + wrapped_info_block + old_content.lstrip
404400
else
405-
magic_comments_block + "\n" + wrapped_info_block + old_content.lstrip
401+
"#{magic_comments_block}\n#{wrapped_info_block}#{old_content.lstrip}"
406402
end
407403
else
408404
# replace the old annotation with the new one
@@ -512,7 +508,7 @@ def annotate(klass, file, header, options = {})
512508
end
513509
rescue StandardError => e
514510
$stderr.puts "Unable to annotate #{file}: #{e.message}"
515-
$stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
511+
$stderr.puts "\t#{e.backtrace.join("\n\t")}" if options[:trace]
516512
end
517513

518514
annotated
@@ -589,7 +585,7 @@ def get_model_class(file)
589585
if File.file?(file_path) && Kernel.require(file_path)
590586
retry
591587
elsif model_path =~ /\//
592-
model_path = model_path.split('/')[1..-1].join('/').to_s
588+
model_path = model_path.split('/')[1..].join('/').to_s
593589
retry
594590
else
595591
raise
@@ -625,7 +621,7 @@ def get_loaded_model_by_path(model_path)
625621
# Revert to the old way but it is not really robust
626622
ObjectSpace.each_object(::Class)
627623
.select do |c|
628-
Class === c && # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
624+
Class === c && # NOTE: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
629625
c.ancestors.respond_to?(:include?) && # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
630626
c.ancestors.include?(ActiveRecord::Base)
631627
end.detect { |c| ActiveSupport::Inflector.underscore(c.to_s) == model_path }
@@ -685,11 +681,11 @@ def annotate_model_file(annotated, file, header, options)
685681
rescue BadModelFileError => e
686682
unless options[:ignore_unknown_models]
687683
$stderr.puts "Unable to annotate #{file}: #{e.message}"
688-
$stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
684+
$stderr.puts "\t#{e.backtrace.join("\n\t")}" if options[:trace]
689685
end
690686
rescue StandardError => e
691687
$stderr.puts "Unable to annotate #{file}: #{e.message}"
692-
$stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
688+
$stderr.puts "\t#{e.backtrace.join("\n\t")}" if options[:trace]
693689
end
694690
end
695691

@@ -720,7 +716,7 @@ def remove_annotations(options = {})
720716
deannotated << klass if deannotated_klass
721717
rescue StandardError => e
722718
$stderr.puts "Unable to deannotate #{File.join(file)}: #{e.message}"
723-
$stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
719+
$stderr.puts "\t#{e.backtrace.join("\n\t")}" if options[:trace]
724720
end
725721
end
726722
puts "Removed annotations from: #{deannotated.join(', ')}"
@@ -780,7 +776,7 @@ def max_schema_info_width(klass, options)
780776
end
781777

782778
def format_default(col_name, max_size, col_type, bare_type_allowance, attrs)
783-
sprintf("# %s:%s %s", mb_chars_ljust(col_name, max_size), mb_chars_ljust(col_type, bare_type_allowance), attrs.join(", ")).rstrip + "\n"
779+
"#{sprintf("# %s:%s %s", mb_chars_ljust(col_name, max_size), mb_chars_ljust(col_type, bare_type_allowance), attrs.join(", ")).rstrip}\n"
784780
end
785781

786782
def width(string)

lib/annotate/annotate_routes.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def routes_file
6767
end
6868

6969
def strip_on_removal(content, header_position)
70-
if header_position == :before
70+
case header_position
71+
when :before
7172
content.shift while content.first == ''
72-
elsif header_position == :after
73+
when :after
7374
content.pop while content.last == ''
7475
end
7576

lib/annotate/annotate_routes/header_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def routes_map(options)
2121
# In old versions of Rake, the first line of output was the cwd. Not so
2222
# much in newer ones. We ditch that line if it exists, and if not, we
2323
# keep the line around.
24-
result.shift if result.first =~ %r{^\(in \/}
24+
result.shift if result.first =~ %r{^\(in /}
2525

2626
ignore_routes = options[:ignore_routes]
2727
regexp_for_ignoring_routes = ignore_routes ? /#{ignore_routes}/ : nil
@@ -57,7 +57,7 @@ def generate
5757
out << comment
5858
return out if contents_without_magic_comments.size.zero?
5959

60-
maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..-1].map { |line| line.split.map(&:size) }
60+
maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..].map { |line| line.split.map(&:size) }
6161

6262
if markdown?
6363
max = maxs.map(&:max).compact.max
@@ -68,7 +68,7 @@ def generate
6868
out << comment(content(contents_without_magic_comments[0], maxs))
6969
end
7070

71-
out += contents_without_magic_comments[1..-1].map { |line| comment(content(markdown? ? line.split(' ') : line, maxs)) }
71+
out += contents_without_magic_comments[1..].map { |line| comment(content(markdown? ? line.split(' ') : line, maxs)) }
7272
out << comment(options[:wrapper_close]) if options[:wrapper_close]
7373

7474
out

0 commit comments

Comments
 (0)