Class: SmartS3Sync::FileTable
- Inherits:
-
Object
- Object
- SmartS3Sync::FileTable
- Defined in:
- lib/smart_s3_sync/file_table.rb
Instance Method Summary collapse
- #copy!(fog_dir) ⇒ Object
-
#initialize(root, prefix = nil) ⇒ FileTable
constructor
A new instance of FileTable.
- #keep?(filename) ⇒ Boolean
- #push(fog_file) ⇒ Object
- #to_copy ⇒ Object
Constructor Details
#initialize(root, prefix = nil) ⇒ FileTable
Returns a new instance of FileTable.
5 6 7 8 9 10 |
# File 'lib/smart_s3_sync/file_table.rb', line 5 def initialize(root, prefix=nil) @map = {} # map of hashes to file destinations @files = [] # single list of files to keep @root = File.(root) # root file destination @prefix = prefix ? prefix.gsub(/(?:^\/)|(?:\/$)/,'') : '' end |
Instance Method Details
#copy!(fog_dir) ⇒ Object
20 21 22 23 24 |
# File 'lib/smart_s3_sync/file_table.rb', line 20 def copy!(fog_dir) @map.sort_by{|(k, target)| -target.destinations.length + (target.source.nil? ? 0 : -100) }.each do |(k, target)| target.copy!(fog_dir) end end |
#keep?(filename) ⇒ Boolean
26 27 28 |
# File 'lib/smart_s3_sync/file_table.rb', line 26 def keep?(filename) @files.include?(filename) end |
#push(fog_file) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/smart_s3_sync/file_table.rb', line 12 def push(fog_file) digest = hash_key(fog_file) # pull cloud calculated hex digest from file @map[digest] ||= FileTarget.new(digest, fog_file.key) # grab or create target destination_filename = File.(strip_prefix(fog_file.key), @root) # calculate local path @files.push destination_filename # add local path to global list of files to keep @map[digest].add_destination(destination_filename) # and add local path to the target end |
#to_copy ⇒ Object
30 31 32 |
# File 'lib/smart_s3_sync/file_table.rb', line 30 def to_copy @map.map{|(k, target)| target.destinations }.flatten end |