Class: Backup::Metadata
- Inherits:
-
Object
- Object
- Backup::Metadata
- 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
-
#backup_information ⇒ BackupInformation
readonly
Information present in the manifest file shipped along with the backup.
-
#manifest_filepath ⇒ Pathname
readonly
Fullpath for the manifest file.
Instance Method Summary collapse
-
#initialize(manifest_filepath) ⇒ Metadata
constructor
A new instance of Metadata.
-
#load! ⇒ Object
Load #BackupInformation from a YAML manifest file on disk.
-
#save! ⇒ Object
Save content from #BackupInformation into a manifest YAML file on disk.
-
#update(**data) ⇒ Object
Update backup information with provided data.
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_information ⇒ BackupInformation (readonly)
Information present in the manifest file shipped along with the backup
11 12 13 |
# File 'lib/backup/metadata.rb', line 11 def backup_information @backup_information end |
#manifest_filepath ⇒ Pathname (readonly)
Fullpath 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
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 |