fancybox2 0.0.9 → 0.0.10

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: 6821e581df48497ebc9870338ab258f9f4c8f4f4301067edef7936f2957452b0
4
- data.tar.gz: 5949d3ee2689bf3dd8c8e4e6256061a8d5c20cafb017cde96856df04d0df217d
3
+ metadata.gz: 3656436f12dfd2d4129e12b7db0ffd45a116698030802589a729ee82bc829948
4
+ data.tar.gz: 75f33ab435919e63a9696ef84a731084060bf3cc654a0a80d427b6c96c38f89a
5
5
  SHA512:
6
- metadata.gz: c98c23a20e13629af2723b789d044e03180e8e07a407f3c842ccd3d314e9b07d8c937a16a5f868c6c49435f999b7bed7956a464f1711092a0f738ba8ab6125d4
7
- data.tar.gz: 14425e0627a2a78f830c7d0dbbd0465d6e009bc308024fa4779ed5c1ea928353574e12c839bb01f9b41e1b8b84eb8e36dddaf25e608f30cac9d63c075af34561
6
+ metadata.gz: fdbd2c3d7e2e69882a53d830c49bf7ee8341c5091bbd43ed55fda77776da36326c16c0c5093a5ed62ef8632357fa0c14e8cc951846352ca9f001fec72b88bad8
7
+ data.tar.gz: 01716640347e04c37b72cdf7fc9b8055c2685beb59381f7869f6b08fc86614eb8a747dfd1611e37e1aa6f6f61424f22da5e1d1363a63d255671d73860132078e
@@ -15,6 +15,22 @@ module Fancybox2
15
15
 
16
16
  version.to_i
17
17
  end
18
+
19
+ def auto(migrations_folder, last_migrated_file_path: nil, logger: nil)
20
+ # Try to read file content, rescue with nil
21
+ content = File.read(last_migrated_file_path) rescue nil
22
+ # Extract last run migration version
23
+ last_run_migration_version = content.to_i
24
+
25
+ runner = new(migrations_folder, logger: logger)
26
+ last_migrated = runner.run last_migrated: last_run_migration_version
27
+ # Update migration status file
28
+ if last_migrated
29
+ f = File.open last_migrated_file_path, 'w'
30
+ f.write last_migrated.version
31
+ f.close
32
+ end
33
+ end
18
34
  end
19
35
 
20
36
  attr_reader :files_path, :current_version, :migrations, :logger
@@ -37,12 +53,16 @@ module Fancybox2
37
53
  from = self.class.extract_and_validate_version_from(from || last_migrated || 0)
38
54
  # This works independently from the direction if migrations' folder contains only migrations of last installed version
39
55
  to = self.class.extract_and_validate_version_from (to || @migrations.last.version)
40
- puts "from: #{from}, to: #{to}, last_migrated: #{last_migrated}"
41
56
  # Select migrations to run
42
57
  to_run, direction = migrations_to_run from, to
43
- # If last_migrated has been specified and direction is :up, remove first migration
44
- if last_migrated && direction == :up
45
- to_run.shift
58
+ # If last_migrated param has been provided, remove some migration from the list depending on direction
59
+ if last_migrated && to_run.any?
60
+ if direction == :up && last_migrated == to_run.first.version
61
+ to_run.shift
62
+ elsif direction == :down
63
+ # We surely have at least 2 migrations in the array, otherwise the direction would've been :up
64
+ to_run.pop
65
+ end
46
66
  end
47
67
  to_run.each do |migration|
48
68
  logger.info "Running migration #{migration.name}"
@@ -68,9 +88,6 @@ module Fancybox2
68
88
  selected = []
69
89
  direction = from <= to ? :up : :down
70
90
  @migrations.each do |m|
71
- puts m.version
72
- # Edge case, no migrations to run
73
- break if from == to
74
91
  # downgrading - Break if we already arrived to "from" migration (e.g from=4, to=2 => 1, >2<, 3, *4*, 5)
75
92
  break if (from > to) && (m.version > from)
76
93
  # upgrading - Break if we already arrived to "to" migration (e.g from=2, to=4 => 1, *2*, 3, >4<, 5)
@@ -78,7 +95,9 @@ module Fancybox2
78
95
  # downgrading - Skip until we arrive to "to" migration (e.g from=4, to=2 => 1, >2<, 3, *4*, 5)
79
96
  next if (from > to) && (m.version < to)
80
97
  # upgrading - Skip until we arrive to "from" migration (e.g from=2, to=4 => 1, *2*, 3, >4<, 5)
81
- next if (from < to) && (m.version < from)
98
+ next if (from <= to) && (m.version < from)
99
+ # Break if we're already out of range
100
+ break if (m.version > from && m.version > to)
82
101
 
83
102
  if m.version <= from
84
103
  selected.prepend m
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fancybox2
4
- VERSION = '0.0.9'
4
+ VERSION = '0.0.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancybox2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk