Class: Backup::Syncer::Cloud::LocalFile
- Inherits:
-
Object
- Object
- Backup::Syncer::Cloud::LocalFile
- Defined in:
- lib/backup/syncer/cloud/local_file.rb
Instance Attribute Summary collapse
-
#md5 ⇒ Object
Returns the value of attribute md5.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.find(dir, excludes = []) ⇒ Object
Returns a Hash of LocalFile objects for each file within
dir, except those matching any of theexcludes. -
.new(*args) ⇒ Object
Return a new LocalFile object if it’s valid.
Instance Method Summary collapse
-
#initialize(path) ⇒ LocalFile
constructor
If
pathcontains invalid UTF-8, it will be sanitized and the LocalFile object will be flagged as invalid. - #invalid? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ LocalFile
If path contains invalid UTF-8, it will be sanitized and the LocalFile object will be flagged as invalid. This is done so @file.path may be logged.
73 74 75 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 73 def initialize(path) @path = sanitize(path) end |
Instance Attribute Details
#md5 ⇒ Object
Returns the value of attribute md5.
8 9 10 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 8 def md5 @md5 end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 7 def path @path end |
Class Method Details
.find(dir, excludes = []) ⇒ Object
Returns a Hash of LocalFile objects for each file within dir, except those matching any of the excludes. Hash keys are the file’s path relative to dir.
14 15 16 17 18 19 20 21 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 14 def find(dir, excludes = []) dir = File.(dir) hash = {} find_md5(dir, excludes).each do |file| hash[file.path.sub(dir + "/", "")] = file end hash end |
.new(*args) ⇒ Object
Return a new LocalFile object if it’s valid. Otherwise, log a warning and return nil.
25 26 27 28 29 30 31 32 33 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 25 def new(*args) file = super if file.invalid? Logger.warn("\s\s[skipping] #{file.path}\n" \ "\s\sPath Contains Invalid UTF-8 byte sequences") file = nil end file end |
Instance Method Details
#invalid? ⇒ Boolean
77 78 79 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 77 def invalid? !!@invalid end |