Class: Chef::Util::Backup
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.
25 26 27 28 |
# File 'lib/chef/util/backup.rb', line 25 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.
22 23 24 |
# File 'lib/chef/util/backup.rb', line 22 def new_resource @new_resource end |
#path ⇒ Object
Returns the value of attribute path.
23 24 25 |
# File 'lib/chef/util/backup.rb', line 23 def path @path end |
Instance Method Details
#backup! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/util/backup.rb', line 30 def backup! if @new_resource.backup != false && @new_resource.backup > 0 && ::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..-1) remainder.each do |backup_to_delete| delete_backup(backup_to_delete) end end end end |