Class: Chef::Util::Backup
- Inherits:
-
Object
- Object
- Chef::Util::Backup
- Defined in:
- lib/chef/util/backup.rb
Instance Attribute Summary collapse
-
#new_resource ⇒ Object
readonly
Returns the value of attribute new_resource.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #backup! ⇒ Object
-
#initialize(new_resource, path = nil) ⇒ Backup
constructor
A new instance of Backup.
Constructor Details
#initialize(new_resource, path = nil) ⇒ Backup
Returns a new instance of Backup.
27 28 29 30 |
# File 'lib/chef/util/backup.rb', line 27 def initialize(new_resource, path = nil) @new_resource = new_resource @path = path.nil? ? new_resource.path : path end |
Instance Attribute Details
#new_resource ⇒ Object (readonly)
Returns the value of attribute new_resource.
24 25 26 |
# File 'lib/chef/util/backup.rb', line 24 def new_resource @new_resource end |
#path ⇒ Object
Returns the value of attribute path.
25 26 27 |
# File 'lib/chef/util/backup.rb', line 25 def path @path end |
Instance Method Details
#backup! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chef/util/backup.rb', line 32 def backup! if @new_resource.backup != false && @new_resource.backup > 0 && ::TargetIO::File.exist?(path) do_backup # Clean up after the number of backups slice_number = @new_resource.backup backup_files = sorted_backup_files if backup_files.length >= @new_resource.backup remainder = backup_files.slice(slice_number..) remainder.each do |backup_to_delete| delete_backup(backup_to_delete) end end end end |