yiffspace-core 0.2.2 → 0.2.3
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/yiffspace/concerns/migration_hooks.rb +51 -0
- data/lib/yiffspace/core/version.rb +1 -1
- data/lib/yiffspace/engine.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46a69cc1d89d8c6b5fd8f2b7fe1a191edad0aefbab824d960eda876c18419408
|
|
4
|
+
data.tar.gz: 81177abd4fc247d0cbac74c88f617bd081872c24470a256c7f56e762ba94f9d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b55e13fbd0cab0a649a5569aeb10407e472cc836995bd19d8ebe23aaf2ed7652d117b119185506ac46388591be1212ed128fac7f17f9a76cf09fd05206130165
|
|
7
|
+
data.tar.gz: d0547e3e8fa76fbd26790f6b59544fb2197505904766c937323c096d97594859901834d546c49dd91078d575228a8b70f5cbe1731e7b3dc13c7a4f849ce01402
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
- Added `before`/`after` hooks to `ActiveRecord::Migration`
|
|
4
|
+
(`YiffSpace::Concerns::MigrationHooks`), for setup and cleanup around a
|
|
5
|
+
whole migration in either direction.
|
|
3
6
|
- **Breaking:** renamed the gem from `yiffspace` to `yiffspace-core`, and split
|
|
4
7
|
it further into standalone gems for complete modularity:
|
|
5
8
|
[`yiffspace-config`](https://github.com/YiffSpace/Gem/tree/master/yiffspace-config)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module YiffSpace
|
|
4
|
+
module Concerns
|
|
5
|
+
# Adds `before`/`after` to ActiveRecord::Migration, for setup and cleanup
|
|
6
|
+
# that should wrap the whole migration in either direction, e.g.:
|
|
7
|
+
#
|
|
8
|
+
# class AddWidgetLimitToConfig < ActiveRecord::Migration[8.1]
|
|
9
|
+
# after { Config.delete_cache }
|
|
10
|
+
#
|
|
11
|
+
# def change
|
|
12
|
+
# add_column(:config, :widget_limit, :integer, null: false, default: 10)
|
|
13
|
+
# end
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# Hooks run on the migration instance and are given the direction (:up or :down). After hooks
|
|
17
|
+
# run in reverse order of registration, and still run if the migration fails, so they can undo
|
|
18
|
+
# what a before hook did. Unlike code at the end of `change`, an after hook runs after a
|
|
19
|
+
# rollback's inverted commands rather than before them. Prepended into ActiveRecord::Migration
|
|
20
|
+
# by YiffSpace::Engine.
|
|
21
|
+
module MigrationHooks
|
|
22
|
+
def self.prepended(base)
|
|
23
|
+
base.extend(ClassMethods)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module ClassMethods
|
|
27
|
+
def before(&block)
|
|
28
|
+
migration_hooks[:before] << block
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def after(&block)
|
|
32
|
+
migration_hooks[:after] << block
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def migration_hooks
|
|
36
|
+
@migration_hooks ||= { before: [], after: [] }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def exec_migration(conn, direction)
|
|
41
|
+
hooks = self.class.migration_hooks
|
|
42
|
+
hooks[:before].each { |hook| instance_exec(direction, &hook) }
|
|
43
|
+
begin
|
|
44
|
+
super
|
|
45
|
+
ensure
|
|
46
|
+
hooks[:after].reverse_each { |hook| instance_exec(direction, &hook) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/yiffspace/engine.rb
CHANGED
|
@@ -9,5 +9,9 @@ module YiffSpace
|
|
|
9
9
|
initializer("yiffspace.assets") do |app|
|
|
10
10
|
app.config.assets.precompile += %w[yiffspace/application.css] if app.config.respond_to?(:assets)
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
initializer("yiffspace.migration_hooks") do
|
|
14
|
+
ActiveSupport.on_load(:active_record) { ActiveRecord::Migration.prepend(YiffSpace::Concerns::MigrationHooks) }
|
|
15
|
+
end
|
|
12
16
|
end
|
|
13
17
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yiffspace-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Donovan_DMC
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-07 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: abbrev
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- lib/yiffspace/concerns/concurrency_methods.rb
|
|
92
92
|
- lib/yiffspace/concerns/conditional_includes.rb
|
|
93
93
|
- lib/yiffspace/concerns/has_bit_flags.rb
|
|
94
|
+
- lib/yiffspace/concerns/migration_hooks.rb
|
|
94
95
|
- lib/yiffspace/configuration.rb
|
|
95
96
|
- lib/yiffspace/core.rb
|
|
96
97
|
- lib/yiffspace/core/version.rb
|