Class: Backup::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/metadata.rb

Defined Under Namespace

Classes: BackupInformation

Constant Summary collapse

YAML_PERMITTED_CLASSES =
[
  ActiveSupport::TimeWithZone, ActiveSupport::TimeZone, Symbol, Time
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_filepath) ⇒ Metadata

Returns a new instance of Metadata.



36
37
38
# File 'lib/backup/metadata.rb', line 36

def initialize(manifest_filepath)
  @manifest_filepath = Pathname.new(manifest_filepath)
end

Instance Attribute Details

#backup_informationBackupInformation (readonly)

Information present in the manifest file shipped along with the backup

Returns:



11
12
13
# File 'lib/backup/metadata.rb', line 11

def backup_information
  @backup_information
end

#manifest_filepathPathname (readonly)

Fullpath for the manifest file

Returns:

  • (Pathname)

    full path for the manifest file



7
8
9
# File 'lib/backup/metadata.rb', line 7

def manifest_filepath
  @manifest_filepath
end

Instance Method Details

#load!Object

Load #BackupInformation from a YAML manifest file on disk



41
42
43
44
45
46
47
# File 'lib/backup/metadata.rb', line 41

def load!
  return @backup_information unless @backup_information.nil?

  manifest_data = load_from_file

  @backup_information = BackupInformation.new(**manifest_data)
end

#save!Object

Save content from #BackupInformation into a manifest YAML file on disk



50
51
52
53
54
55
56
# File 'lib/backup/metadata.rb', line 50

def save!
  Dir.chdir(File.dirname(manifest_filepath)) do
    File.open(manifest_filepath, 'w+') do |file|
      file << backup_information.to_h.to_yaml.gsub(/^---\n/, '')
    end
  end
end

#update(**data) ⇒ Object

Update backup information with provided data

Parameters:

  • data (Hash)

    arguments matching #BackupInformation keyword arguments



61
62
63
64
65
66
67
# File 'lib/backup/metadata.rb', line 61

def update(**data)
  @backup_information ||= BackupInformation.new

  data.each_pair do |key, value|
    backup_information[key] = value
  end
end