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.
75 76 77 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 75 def initialize(path) @path = sanitize(path) end |
Instance Attribute Details
#md5 ⇒ Object
Returns the value of attribute md5.
9 10 11 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 9 def md5 @md5 end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 8 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.
16 17 18 19 20 21 22 23 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 16 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.
27 28 29 30 31 32 33 34 35 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 27 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
79 80 81 |
# File 'lib/backup/syncer/cloud/local_file.rb', line 79 def invalid? !!@invalid end |