Skip to content

Commit 8ba2200

Browse files
committed
fix rubocop
1 parent 5292855 commit 8ba2200

20 files changed

+73
-17
lines changed

.github/workflows/checkstyle.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ jobs:
2424
- name: Set up Ruby ${{ matrix.ruby-version }}
2525
uses: ruby/setup-ruby@v1
2626
with:
27-
ruby-version: 2.7
28-
bundler: 1
27+
ruby-version: 3.2
2928
bundler-cache: true
3029

30+
- name: Install rubocop
31+
run: gem install rubocop -v "~>1.63"
32+
3133
- name: Run rubocop
3234
run: bundle exec rubocop --parallel --fail-level R

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
timeout-minutes: 15
1919

2020
strategy:
21+
fail-fast: false
2122
matrix:
2223
ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3]
2324

@@ -38,9 +39,9 @@ jobs:
3839
- uses: actions/cache@v4
3940
with:
4041
path: vendor/bundle
41-
key: ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v2-${{ hashFiles('rails-data-migrations.gemspec', 'Appraisals') }}
42+
key: ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3-${{ hashFiles('rails-data-migrations.gemspec', 'Appraisals') }}
4243
restore-keys: |
43-
${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v2-
44+
${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3-
4445
4546
- name: Install dependencies
4647
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
/.idea/
1111
spec/db/
1212
gemfiles/
13+
vendor/
1314
*.gem

.rubocop.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ AllCops:
33
- 'vendor/**/*'
44
- 'gemfiles/**/*'
55

6-
Layout/TrailingBlankLines:
6+
Gemspec/RequiredRubyVersion:
7+
Enabled: false
8+
9+
Gemspec/RubyVersionGlobalsUsage:
10+
Enabled: false
11+
12+
Layout/TrailingEmptyLines:
713
Enabled: false
814

915
Metrics/BlockLength:
@@ -12,6 +18,10 @@ Metrics/BlockLength:
1218
Metrics/LineLength:
1319
Max: 120
1420

21+
Naming/FileName:
22+
Exclude:
23+
- lib/rails-data-migrations.rb
24+
1525
Style/Documentation:
1626
Enabled: false
1727

Appraisals

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
ruby_version = Gem::Version.new(RUBY_VERSION)
24

35
if ruby_version < Gem::Version.new('2.7.0')
@@ -18,19 +20,23 @@ if ruby_version < Gem::Version.new('3.0.0')
1820

1921
appraise 'rails-5.1' do
2022
gem 'rails', '~> 5.1.0'
23+
gem 'sqlite3', '~> 1.3.6'
2124
end
2225

2326
appraise 'rails-5.2' do
2427
gem 'rails', '~> 5.2.0'
28+
gem 'sqlite3', '~> 1.3.6'
2529
end
2630
end
2731

2832
if ruby_version >= Gem::Version.new('2.5.0')
2933
appraise 'rails-6.0' do
3034
gem 'rails', '~> 6.0.0'
35+
gem 'sqlite3', '~> 1.4.0'
3136
end
3237

3338
appraise 'rails-6.1' do
3439
gem 'rails', '~> 6.1.0'
40+
gem 'sqlite3', '~> 1.4.0'
3541
end
3642
end

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
# Specify your gem's dependencies in activerecord-data-migrations.gemspec

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'rspec/core/rake_task'
35

lib/active_record/data_migration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rails/version'
24

35
module ActiveRecord

lib/generators/data_migration_generator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require 'rails/generators'
24
require 'rails-data-migrations'
35

46
class DataMigrationGenerator < Rails::Generators::NamedBase
5-
source_root File.expand_path('../templates', __FILE__)
7+
source_root File.expand_path('templates', __dir__)
68

79
def create_migration_file
810
migration_file_name =

lib/generators/templates/data_migration_generator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ClassName < ActiveRecord::DataMigration
24
def up
35
# put your code here

lib/rails-data-migrations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# rubocop:disable Naming/FileName
1+
# frozen_string_literal: true
2+
23
require 'rails'
34
require 'active_record'
45
require 'active_record/data_migration'
56
require 'rails_data_migrations/version'
67
require 'rails_data_migrations/log_entry'
78
require 'rails_data_migrations/migrator'
89
require 'rails_data_migrations/railtie'
9-
# rubocop:enable Naming/FileName

lib/rails_data_migrations/log_entry.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module RailsDataMigrations
24
class LogEntry < ::ActiveRecord::SchemaMigration
35
class << self
46
def table_name
5-
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
7+
"#{ActiveRecord::Base.table_name_prefix}data_migrations#{ActiveRecord::Base.table_name_suffix}"
68
end
79

810
def index_name

lib/rails_data_migrations/migrator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RailsDataMigrations
24
class Migrator < ::ActiveRecord::Migrator
35
MIGRATOR_SALT = 2053462855
@@ -61,7 +63,7 @@ def list_pending_migrations
6163
already_migrated = get_all_versions
6264
list_migrations.reject { |m| already_migrated.include?(m.version) }
6365
else
64-
open(migrations_path).pending_migrations
66+
open(migrations_path).pending_migrations # rubocop:disable Security/Open
6567
end
6668
end
6769

lib/rails_data_migrations/railtie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rails'
24

35
module RailsDataMigrations

lib/rails_data_migrations/version.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RailsDataMigrations
2-
VERSION = '1.2.0'.freeze
4+
VERSION = '1.2.0'
35
end

lib/tasks/data_migrations.rake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# frozen_string_literal: true
2+
13
require 'rake'
24

35
namespace :data do
46
def apply_single_migration(direction, version)
57
raise 'VERSION is required' unless version
8+
69
RailsDataMigrations::Migrator.run_migration(
710
direction,
811
RailsDataMigrations::Migrator.migrations_path,
@@ -42,7 +45,8 @@ namespace :data do
4245
desc 'Skip single data migration using VERSION'
4346
task skip: :init_migration do
4447
version = ENV['VERSION'].to_i
45-
raise 'VERSION is required' unless version > 0
48+
raise 'VERSION is required' unless version.positive?
49+
4650
if RailsDataMigrations::LogEntry.where(version: version).any?
4751
puts "data migration #{version} was already applied."
4852
else

rails-data-migrations.gemspec

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
lib = File.expand_path('lib', __dir__)
24
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
35
require 'rails_data_migrations/version'
46

@@ -23,6 +25,14 @@ Gem::Specification.new do |spec|
2325
spec.add_development_dependency 'appraisal', '~> 2.1'
2426
spec.add_development_dependency 'rake', '>= 12.3.3'
2527
spec.add_development_dependency 'rspec', '3.5.0'
26-
spec.add_development_dependency 'rubocop', '0.52.1'
27-
spec.add_development_dependency 'sqlite3', '~> 1.3.6'
28+
29+
# spec.add_development_dependency(
30+
# 'rubocop',
31+
# Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') ? '~> 1.63' : '0.52.1'
32+
# )
33+
#
34+
# spec.add_development_dependency(
35+
# 'sqlite3',
36+
# Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') ? '~> 1.3' : '~> 1.3.6'
37+
# )
2838
end

spec/data_migrations_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe RailsDataMigrations do
@@ -44,7 +46,7 @@
4446
end
4547

4648
def load_rake_rasks
47-
load File.expand_path('../../lib/tasks/data_migrations.rake', __FILE__)
49+
load File.expand_path('../lib/tasks/data_migrations.rake', __dir__)
4850
Rake::Task.define_task(:environment)
4951
end
5052

spec/generators/data_migration_generator_spec.rb

Whitespace-only changes.

spec/spec_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
require 'rails/generators'
24
require 'rake'
35

4-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
6+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
57
require 'rails-data-migrations'
68

79
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'

0 commit comments

Comments
 (0)