Sha256: e1f4f46fd3850eabdb157753b6b45436c5067a916f941d86bb32969f8da65014

Contents?: true

Size: 1.22 KB

Versions: 24

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'active_model'
require_relative '../crud/json_file'
require_relative '../services/migration_version/hydrator_service'
require_relative '../validators/version_validator'

module Dsu
  module Models
    # This class represents a dsu migration_version.
    class MigrationVersion < Crud::JsonFile
      include Support::Fileable

      attr_reader :options

      def initialize(version: nil, options: {})
        super(migration_version_path)

        FileUtils.mkdir_p migration_version_folder

        @options = options || {}
        @version = version and return if version

        file_hash = if exist?
          read do |migration_version_hash|
            hydrated_hash =
              Services::MigrationVersion::HydratorService.new(migration_version_hash: migration_version_hash).call
            migration_version_hash.merge!(hydrated_hash)
          end
        end

        self.version = file_hash.try(:[], :version) || 0
      end

      # Returns true if the current dsu install is the
      # current migration version.
      def current_migration?
        version == Dsu::Migration::VERSION
      end

      def to_h
        {
          version: version
        }
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dsu-2.4.2 lib/dsu/models/migration_version.rb
dsu-2.4.1 lib/dsu/models/migration_version.rb
dsu-2.4.0 lib/dsu/models/migration_version.rb
dsu-2.3.2 lib/dsu/models/migration_version.rb
dsu-2.3.1 lib/dsu/models/migration_version.rb
dsu-2.3.0 lib/dsu/models/migration_version.rb
dsu-2.2.2 lib/dsu/models/migration_version.rb
dsu-2.2.1 lib/dsu/models/migration_version.rb
dsu-2.2.0 lib/dsu/models/migration_version.rb
dsu-2.2.0.rc.2 lib/dsu/models/migration_version.rb
dsu-2.2.0.rc.1 lib/dsu/models/migration_version.rb
dsu-2.1.4 lib/dsu/models/migration_version.rb
dsu-2.1.3 lib/dsu/models/migration_version.rb
dsu-2.1.2 lib/dsu/models/migration_version.rb
dsu-2.1.1 lib/dsu/models/migration_version.rb
dsu-2.0.8 lib/dsu/models/migration_version.rb
dsu-2.0.7 lib/dsu/models/migration_version.rb
dsu-2.0.6 lib/dsu/models/migration_version.rb
dsu-2.0.5 lib/dsu/models/migration_version.rb
dsu-2.0.4 lib/dsu/models/migration_version.rb