outrigger 2.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 855ecd62fb346fb6e0ee6dcebc3fa2812132a6a71473544835453c6eb9851d6f
4
- data.tar.gz: 40c0f0f3ce60783d2fcc8612090f369a8ca66e0174cc38d4c83a299eaaee57af
3
+ metadata.gz: 470f381099cffd17d79737efc2f7501ab70a3de44df06c92e0a14b579314bd76
4
+ data.tar.gz: 5fe33a5c351cb9a0511a62c0480d15a23e0cb4fe67bfd32f67aec9eeaefd9b5e
5
5
  SHA512:
6
- metadata.gz: b9dd84dc5f5eda731e476375b772a8250ec7fdf27319a73ffc6538c8a57de78d2b842a545bffde5135d2369c17aa33ee764602dc8f4d3785e1764ca791734e29
7
- data.tar.gz: 239d9517aefd40f773a71887ba83885ac82ad1f62d5e9ec7c693d48fcce107ba41fddb6a3d0a7e7904b3a36b7b4bcec24f5945d686a1781609c80fdb55c60777
6
+ metadata.gz: 53692e56afb3a76874bb7000811daed3cfac224e7dc344e946bf78cb97b2b44fdabc28529e36f12fb901d8d92f15d86183c9b42cfdd03cd90dbd566e9be68b2c
7
+ data.tar.gz: fd62d320a416ecbdeb31ef47efd5102097e55407f3213217c9f22b340287429d46bf636e4a4a91197082432e4c50fb4d048e919dcd80563e5cdffabcadfe470c
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  begin
@@ -6,14 +8,6 @@ begin
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
 
8
10
  task(default: :spec)
9
- rescue LoadError # rubocop:disable Lint/HandleExceptions
10
- # no rspec available
11
- end
12
-
13
- task :console do
14
- require 'irb'
15
- require 'irb/completion'
16
- require 'outrigger'
17
- ARGV.clear
18
- IRB.start
11
+ rescue LoadError
12
+ nil
19
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module Migration
@@ -5,6 +7,7 @@ module RuboCop
5
7
  def on_class(node)
6
8
  _name, _superclass, body = *node
7
9
  return unless body && migration_class?(node)
10
+
8
11
  check(node, body)
9
12
  end
10
13
 
@@ -33,6 +36,7 @@ module RuboCop
33
36
  message: 'No allowed tags have been defined in the RuboCop configuration.'
34
37
  elsif tag
35
38
  return if allowed_tags.include? tag.children.last.to_a.last
39
+
36
40
  add_offense tag,
37
41
  location: :expression,
38
42
  message: "Tags may only be one of #{allowed_tags}."
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Outrigger
4
+ module Migrator
5
+ def runnable
6
+ result = super
7
+ return result unless Outrigger.ordered
8
+
9
+ # re-order according to configuration
10
+ result.sort_by! { |m| [Outrigger.ordered[m.tags.first] || 0, m.version] }
11
+ result.reverse! if down?
12
+ result
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Outrigger
2
4
  class Railtie < Rails::Railtie
3
5
  railtie_name :taggable_migrations
@@ -8,8 +10,9 @@ module Outrigger
8
10
 
9
11
  initializer 'extend_migrations' do
10
12
  ActiveSupport.on_load :active_record do
11
- ActiveRecord::Migration.send :include, Outrigger::Taggable
12
- ActiveRecord::MigrationProxy.send :include, Outrigger::TaggableProxy
13
+ ActiveRecord::Migration.include(Outrigger::Taggable)
14
+ ActiveRecord::MigrationProxy.include(Outrigger::TaggableProxy)
15
+ ActiveRecord::Migrator.prepend(Outrigger::Migrator)
13
16
  end
14
17
  end
15
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Outrigger
2
4
  module Taggable
3
5
  def self.included(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Outrigger
2
4
  module TaggableProxy
3
5
  def self.included(_body)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Outrigger
2
- VERSION = '2.1.1'.freeze
4
+ VERSION = '3.0.0'
3
5
  end
data/lib/outrigger.rb CHANGED
@@ -1,13 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record' unless defined? ActiveRecord
2
4
 
5
+ require 'outrigger/migrator'
3
6
  require 'outrigger/taggable'
4
7
  require 'outrigger/taggable_proxy'
5
8
 
6
9
  require 'outrigger/railtie' if defined? Rails::Railtie
7
10
 
8
11
  module Outrigger
9
- def self.filter(*tags)
10
- tags = tags.flatten.map(&:to_sym)
11
- proc { |migration| (tags - migration.tags).empty? }
12
+ class << self
13
+ attr_accessor :ordered
14
+
15
+ def filter(*tags)
16
+ tags = tags.flatten.map(&:to_sym)
17
+ proc { |migration| (tags - migration.tags).empty? }
18
+ end
12
19
  end
13
20
  end
@@ -1,13 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :db do
2
4
  namespace :migrate do
3
5
  desc 'Run migrations for a Tag'
4
6
  task tagged: %i[environment load_config] do |_t, args|
5
7
  puts("Migrating Tags: #{args.extras}")
6
- if ActiveRecord.gem_version >= Gem::Version.new('5.2.0')
7
- ActiveRecord::Base.connection.migration_context.migrate(nil, &Outrigger.filter(args.extras))
8
- else
9
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, &Outrigger.filter(args.extras))
10
- end
8
+ ActiveRecord::Base.connection.migration_context.migrate(nil, &Outrigger.filter(args.extras))
11
9
  end
12
10
  end
13
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec path: '../../'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec path: '../../'
@@ -1,7 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'outrigger/cops/migration/tagged'
3
4
 
4
- RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/BlockLength
5
+ RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable RSpec/FilePath
5
6
  let(:config_hash) do
6
7
  {
7
8
  'Migration/Tagged' => {
@@ -23,7 +24,7 @@ RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/Bloc
23
24
  RUBY
24
25
  end
25
26
 
26
- subject(:cop) { described_class.new(config) }
27
+ subject(:cop) { described_class.new(config) } # rubocop:disable RSpec/LeadingSubject
27
28
 
28
29
  shared_examples_for 'valid migrations' do
29
30
  it 'passes valid versioned migration' do
@@ -32,10 +33,10 @@ RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/Bloc
32
33
  end
33
34
  end
34
35
 
35
- context 'valid config' do # rubocop:disable Metrics/BlockLength
36
+ context 'with valid config' do
36
37
  include_examples 'valid migrations'
37
38
 
38
- context 'missing tags' do
39
+ context 'with missing tags' do
39
40
  let(:migration_class) do
40
41
  <<~RUBY
41
42
  class Test < ActiveRecord::Migration[4.2]
@@ -52,7 +53,7 @@ RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/Bloc
52
53
  end
53
54
  end
54
55
 
55
- context 'invalid tag' do
56
+ context 'with invalid tag' do
56
57
  let(:migration_class) do
57
58
  <<~RUBY
58
59
  class Test < ActiveRecord::Migration[4.2]
@@ -71,7 +72,7 @@ RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/Bloc
71
72
  end
72
73
  end
73
74
 
74
- context 'invalid config' do
75
+ context 'with invalid config' do
75
76
  let(:config_hash) do
76
77
  {
77
78
  'Migration/Tagged' => {
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Outrigger
4
+ describe Migrator do
5
+ around do |example|
6
+ Outrigger.ordered = { predeploy: -1, postdeploy: 1 }
7
+ example.call
8
+ ensure
9
+ Outrigger.ordered = nil
10
+ end
11
+
12
+ let(:migrations) do
13
+ [PostDeployMigration.new(nil, 1), UntaggedMigration.new(nil, 2), PreDeployMigration.new(nil, 3),
14
+ MultiMigration.new(nil, 4)]
15
+ end
16
+
17
+ before do
18
+ allow(ActiveRecord::InternalMetadata).to receive(:create_table)
19
+ end
20
+
21
+ it 'sorts' do
22
+ schema_migration = object_double(ActiveRecord::SchemaMigration, create_table: nil, all_versions: [])
23
+ expect(ActiveRecord::Migrator.new(:up, migrations, schema_migration).runnable.map(&:class)).to eq(
24
+ [
25
+ PreDeployMigration, MultiMigration, UntaggedMigration, PostDeployMigration
26
+ ]
27
+ )
28
+ end
29
+
30
+ it 'reverse sorts when going down' do
31
+ schema_migration = object_double(ActiveRecord::SchemaMigration, create_table: nil, all_versions: [1, 2, 3, 4])
32
+ expect(ActiveRecord::Migrator.new(:down, migrations, schema_migration).runnable.map(&:class)).to eq(
33
+ [
34
+ PostDeployMigration, UntaggedMigration, MultiMigration, PreDeployMigration
35
+ ]
36
+ )
37
+ end
38
+ end
39
+ end
@@ -1,15 +1,15 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Outrigger do
4
4
  describe 'filter' do
5
- it 'should return a proc that tests migrations' do
6
- filter = Outrigger.filter(:predeploy)
5
+ it 'returns a proc that tests migrations' do
6
+ filter = described_class.filter(:predeploy)
7
7
 
8
8
  expect(filter.call(PreDeployMigration)).to eq(true)
9
9
  end
10
10
 
11
- it 'should accept multiple tags' do
12
- filter = Outrigger.filter(:predeploy, :postdeploy)
11
+ it 'accepts multiple tags' do
12
+ filter = described_class.filter(:predeploy, :postdeploy)
13
13
 
14
14
  expect(filter.call(MultiMigration)).to eq(true)
15
15
  expect(filter.call(PreDeployMigration)).to eq(false)
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Outrigger::Railtie do
4
- let(:subject) { Outrigger::Railtie }
5
-
6
4
  it 'provides a railtie_name' do
7
- expect(subject.railtie_name).to eq 'taggable_migrations'
5
+ expect(described_class.railtie_name).to eq 'taggable_migrations'
8
6
  end
9
7
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  class TestProxy
4
4
  include Outrigger::TaggableProxy
@@ -6,7 +6,7 @@ class TestProxy
6
6
  end
7
7
 
8
8
  describe Outrigger::TaggableProxy do
9
- it 'it should delegate tags to the migration' do
9
+ it 'delegates tags to the migration' do
10
10
  proxy = TestProxy.new
11
11
  proxy.migration = PreDeployMigration.new
12
12
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Outrigger::Taggable do
4
4
  it 'PreDeployMigration should be predeploy' do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  SimpleCov.start do
3
5
  add_filter 'lib/outrigger/version.rb'
@@ -7,14 +9,16 @@ end
7
9
  SimpleCov.minimum_coverage(85)
8
10
 
9
11
  require 'bundler/setup'
12
+ require 'byebug'
10
13
  require 'rails/railtie'
11
14
  require 'rubocop'
12
15
  require 'rubocop/rspec/support'
13
16
 
14
17
  require 'outrigger'
15
18
 
16
- ActiveRecord::Migration.send :include, Outrigger::Taggable
17
- ActiveRecord::MigrationProxy.send :include, Outrigger::TaggableProxy
19
+ ActiveRecord::Migration.include(Outrigger::Taggable)
20
+ ActiveRecord::MigrationProxy.include(Outrigger::TaggableProxy)
21
+ ActiveRecord::Migrator.prepend(Outrigger::Migrator)
18
22
 
19
23
  class PreDeployMigration < ActiveRecord::Migration[5.0]
20
24
  tag :predeploy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Bowman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '6.2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.0'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6.2'
@@ -34,23 +34,37 @@ dependencies:
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '2.2'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '2.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: byebug
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '11.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '11.1'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: railties
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - ">="
52
66
  - !ruby/object:Gem::Version
53
- version: '5.0'
67
+ version: '6.0'
54
68
  - - "<"
55
69
  - !ruby/object:Gem::Version
56
70
  version: '6.2'
@@ -60,7 +74,7 @@ dependencies:
60
74
  requirements:
61
75
  - - ">="
62
76
  - !ruby/object:Gem::Version
63
- version: '5.0'
77
+ version: '6.0'
64
78
  - - "<"
65
79
  - !ruby/object:Gem::Version
66
80
  version: '6.2'
@@ -98,42 +112,70 @@ dependencies:
98
112
  requirements:
99
113
  - - "~>"
100
114
  - !ruby/object:Gem::Version
101
- version: 0.52.0
115
+ version: '1.20'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.20'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop-rake
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.6'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.6'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rubocop-rspec
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '2.4'
102
144
  type: :development
103
145
  prerelease: false
104
146
  version_requirements: !ruby/object:Gem::Requirement
105
147
  requirements:
106
148
  - - "~>"
107
149
  - !ruby/object:Gem::Version
108
- version: 0.52.0
150
+ version: '2.4'
109
151
  - !ruby/object:Gem::Dependency
110
152
  name: simplecov
111
153
  requirement: !ruby/object:Gem::Requirement
112
154
  requirements:
113
155
  - - "~>"
114
156
  - !ruby/object:Gem::Version
115
- version: '0'
157
+ version: '0.21'
116
158
  type: :development
117
159
  prerelease: false
118
160
  version_requirements: !ruby/object:Gem::Requirement
119
161
  requirements:
120
162
  - - "~>"
121
163
  - !ruby/object:Gem::Version
122
- version: '0'
164
+ version: '0.21'
123
165
  - !ruby/object:Gem::Dependency
124
166
  name: wwtd
125
167
  requirement: !ruby/object:Gem::Requirement
126
168
  requirements:
127
169
  - - "~>"
128
170
  - !ruby/object:Gem::Version
129
- version: '1.3'
171
+ version: '1.4'
130
172
  type: :development
131
173
  prerelease: false
132
174
  version_requirements: !ruby/object:Gem::Requirement
133
175
  requirements:
134
176
  - - "~>"
135
177
  - !ruby/object:Gem::Version
136
- version: '1.3'
178
+ version: '1.4'
137
179
  description: Migrations
138
180
  email:
139
181
  executables: []
@@ -143,17 +185,16 @@ files:
143
185
  - Rakefile
144
186
  - lib/outrigger.rb
145
187
  - lib/outrigger/cops/migration/tagged.rb
188
+ - lib/outrigger/migrator.rb
146
189
  - lib/outrigger/railtie.rb
147
190
  - lib/outrigger/taggable.rb
148
191
  - lib/outrigger/taggable_proxy.rb
149
192
  - lib/outrigger/version.rb
150
193
  - lib/tasks/outrigger.rake
151
- - spec/gemfiles/rails-5.0.gemfile
152
- - spec/gemfiles/rails-5.1.gemfile
153
- - spec/gemfiles/rails-5.2.gemfile
154
- - spec/gemfiles/rails-6.0.gemfile
155
- - spec/gemfiles/rails-6.1.gemfile
194
+ - spec/gemfiles/rails_6.0.gemfile
195
+ - spec/gemfiles/rails_6.1.gemfile
156
196
  - spec/outrigger/cops/migration/tagged_spec.rb
197
+ - spec/outrigger/migrator_spec.rb
157
198
  - spec/outrigger/outrigger_spec.rb
158
199
  - spec/outrigger/railtie_spec.rb
159
200
  - spec/outrigger/taggable_proxy_spec.rb
@@ -171,24 +212,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
212
  requirements:
172
213
  - - ">="
173
214
  - !ruby/object:Gem::Version
174
- version: 2.3.0
215
+ version: '2.6'
175
216
  required_rubygems_version: !ruby/object:Gem::Requirement
176
217
  requirements:
177
218
  - - ">="
178
219
  - !ruby/object:Gem::Version
179
220
  version: '0'
180
221
  requirements: []
181
- rubygems_version: 3.2.15
222
+ rubygems_version: 3.2.24
182
223
  signing_key:
183
224
  specification_version: 4
184
225
  summary: Tag migrations and run them separately
185
226
  test_files:
186
- - spec/gemfiles/rails-5.0.gemfile
187
- - spec/gemfiles/rails-5.1.gemfile
188
- - spec/gemfiles/rails-5.2.gemfile
189
- - spec/gemfiles/rails-6.0.gemfile
190
- - spec/gemfiles/rails-6.1.gemfile
227
+ - spec/gemfiles/rails_6.0.gemfile
228
+ - spec/gemfiles/rails_6.1.gemfile
191
229
  - spec/outrigger/cops/migration/tagged_spec.rb
230
+ - spec/outrigger/migrator_spec.rb
192
231
  - spec/outrigger/outrigger_spec.rb
193
232
  - spec/outrigger/railtie_spec.rb
194
233
  - spec/outrigger/taggable_proxy_spec.rb
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', '~> 5.0.7'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', '~> 5.1.6'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', '~> 5.2.0'