yiffspace-fixers 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 410c5b95f3bf8123d1cb102448230885bfd3f9017fc7b58e9b98a57c744c3e6b
4
- data.tar.gz: e1676aa2ef8a186c1886ae40b02354acc6dc1ffe0cb77c272f623ff218c0f5cb
3
+ metadata.gz: acd62a82b8d0b1a4e8b58612b8e1fa68fa80bee2b1d32d0ec9f3dd6566aac75e
4
+ data.tar.gz: 87ec2fcee2b7f9259dc808f8d7a524a3e91db0c4820d7076e5d820988f2593be
5
5
  SHA512:
6
- metadata.gz: 40c9c084ed52eadd521474d6a08f0a96d1dc521ce8746af8d2180ff186a99df2fce72e424672b47b00e42f64bda790f83d5a1cc8202ef0b06646031bd1ce189f
7
- data.tar.gz: 876bade619a962e9c7035bb8263f51c4adc977fe0cb2afb6db4625eed7528115d4f24ac785b0fe2eae736594575b808025a46e6baad5bc41daad85e2e41b97ca
6
+ metadata.gz: c77170c7d1ada931e3101f9637a50b74f9cfa7306f0638642830dd318b06e71aebf31c4d8b122c38326966666511340d9871b1b7519e9807b2f09117a4b12eed
7
+ data.tar.gz: f2c7eae550ce7fe2039bd7c5478346bd1634848050020381ea551882fbdcff083e36eb6b2e3b05b4bec77e043fe3c7860fdaf6ece9758e22d228bfc18fa3a61d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## Unreleased
2
2
 
3
+ - Added `run_fix!`, the same as `run_fix` but runs fixes even if they're already applied.
3
4
  - Migrations can run fixes themselves with `run_fix(id_or_name)`, which runs and records any of
4
5
  them not yet applied, and does nothing on rollback. `fixes:migrate_all` reads these calls out
5
6
  of pending migrations and folds those fixes into the migration's step instead of scheduling
data/README.md CHANGED
@@ -52,7 +52,8 @@ end
52
52
  A migration can also run a fix itself with `run_fix`, inside its own transaction - skipped if the
53
53
  fix is already applied, and when the migration is rolled back. `fixes:migrate_all` leaves those
54
54
  fixes to the migration rather than running them on their own, and a fix run this way can
55
- `requires_migration!` the migration running it:
55
+ `requires_migration!` the migration running it. `run_fix!` does the same, but runs the fix even if
56
+ it's already applied:
56
57
 
57
58
  ```ruby
58
59
  class AddWidgetType < ActiveRecord::Migration[8.1]
@@ -29,7 +29,7 @@ module YiffSpace
29
29
  # Each fix it covers is run and recorded the same as YiffSpace::FixTracker.run!, unless it's
30
30
  # already applied, and inside the migration's transaction. Fixes can't be undone, so it does
31
31
  # nothing when the migration is rolled back. A fix run this way can requires_migration! the
32
- # migration running it.
32
+ # migration running it. `run_fix!` does the same, but runs fixes even if already applied.
33
33
  module RequiresFix
34
34
  # Raised when a migration runs before one of its required fixes has been applied.
35
35
  class FixRequired < StandardError; end
@@ -37,9 +37,9 @@ module YiffSpace
37
37
  # Same idea as YiffSpace::FixTracker::REQUIRES_MIGRATION_PATTERN - lets
38
38
  # YiffSpace::MigrationSync read the fixes a migration runs out of its file, so
39
39
  # `fixes:migrate_all` leaves them to the migration instead of running them on their own.
40
- RUN_FIX_PATTERN = /^\s*run_fix\(\s*(?:(\d+)|["']([^"']+)["'])\s*\)/
40
+ RUN_FIX_PATTERN = /^\s*run_fix!?\(\s*(?:(\d+)|["']([^"']+)["'])\s*\)/
41
41
 
42
- # The id_or_name of every run_fix call in a migration file.
42
+ # The id_or_name of every run_fix/run_fix! call in a migration file.
43
43
  def self.fixes_run_by(path)
44
44
  File.read(path).scan(RUN_FIX_PATTERN).map { |id, name| id ? id.to_i : name }
45
45
  end
@@ -70,24 +70,33 @@ module YiffSpace
70
70
 
71
71
  # id_or_name: same as requires_fix.
72
72
  def run_fix(id_or_name)
73
+ run_fixes(id_or_name, force: false)
74
+ end
75
+
76
+ # Same as run_fix, but runs fixes even if they're already applied.
77
+ def run_fix!(id_or_name)
78
+ run_fixes(id_or_name, force: true)
79
+ end
80
+
81
+ private
82
+
83
+ def run_fixes(id_or_name, force:)
73
84
  return if reverting?
74
85
 
75
86
  names = YiffSpace::FixTracker.resolve(id_or_name)
76
87
  raise(ArgumentError, "#{self.class.name} runs fix #{id_or_name.inspect}, which does not exist") if names.empty?
77
88
 
78
89
  names.each do |name|
79
- if YiffSpace::FixTracker.applied?(name)
90
+ if !force && YiffSpace::FixTracker.applied?(name)
80
91
  say("#{name} already applied, skipping")
81
92
  else
82
- say_with_time("run_fix(#{name.inspect})") do
93
+ say_with_time("run_fix#{'!' if force}(#{name.inspect})") do
83
94
  YiffSpace::FixTracker.running_migration(version) { YiffSpace::FixTracker.run!(YiffSpace::FixTracker.fix_path(name)) }
84
95
  end
85
96
  end
86
97
  end
87
98
  end
88
99
 
89
- private
90
-
91
100
  def check_required_fixes!
92
101
  self.class.required_fixes.each do |id_or_name|
93
102
  names = YiffSpace::FixTracker.resolve(id_or_name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module YiffSpace
4
4
  module Fixers
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yiffspace-fixers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan_DMC