Class: Dsu::Models::MigrationVersion

Inherits:
Crud::JsonFile show all
Includes:
Support::Fileable
Defined in:
lib/dsu/models/migration_version.rb

Overview

This class represents a dsu migration_version.

Constant Summary

Constants included from Support::Fileable

Support::Fileable::MIGRATION_VERSION_FILE_NAME

Instance Attribute Summary collapse

Attributes inherited from Crud::JsonFile

#file_path, #version

Instance Method Summary collapse

Methods included from Support::Fileable

#backup_folder_for, #config_file_name, #config_folder, #config_path, #current_project_file, #current_project_file_name, #dsu_folder, #entries_file_name, #entries_folder, #entries_path, #gem_dir, #migration_version_folder, #migration_version_path, #project_file_for, #project_folder_for, #projects_folder, #root_folder, #seed_data_dsu_configuration_for, #seed_data_dsu_folder_for, #temp_folder, #theme_file_name, #themes_folder, #themes_path

Methods inherited from Crud::JsonFile

delete, #delete, #delete!, delete!, file_does_not_exist_message, #file_exist?, file_exist?, parse, #persisted?, read, read!, #reload, #save, #save!, #to_model, #update_version!, #write, write, #write!, write!

Constructor Details

#initialize(version: nil, options: {}) ⇒ MigrationVersion

Returns a new instance of MigrationVersion.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dsu/models/migration_version.rb', line 17

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/dsu/models/migration_version.rb', line 13

def options
  @options
end

Instance Method Details

#current_migration?Boolean

Returns true if the current dsu install is the current migration version.

Returns:

  • (Boolean)


38
39
40
# File 'lib/dsu/models/migration_version.rb', line 38

def current_migration?
  version == Dsu::Migration::VERSION
end

#to_hObject



42
43
44
45
46
# File 'lib/dsu/models/migration_version.rb', line 42

def to_h
  {
    version: version
  }
end