Class: FileComposer::Stores::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/file_composer/stores/local.rb

Overview

File copier from local file system to the local file system but with a sharded path with YYYY/MM/DD using the passed in date. The date will default to the current date in UTC unless specified otherwise. The filename passed in will be used to determine the extension but the destination will create a new GUID to use as the filename. For example:

  • input: some/path/input.txt

  • output: 2020/06/25/82d042eb-9592-47f1-8019-2f06f73dc053.txt

The reason it returns a completely random name is to ensure the file truly has a unique place to live, independent of what was passed in. You are free to change these assumptions by creating and using your own store if any of these implementation details do not fit your specific use case.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date: Time.now.utc.to_date, root: '') ⇒ Local

Returns a new instance of Local.



26
27
28
29
30
31
# File 'lib/file_composer/stores/local.rb', line 26

def initialize(date: Time.now.utc.to_date, root: '')
  @date = date
  @root = root.to_s

  freeze
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



24
25
26
# File 'lib/file_composer/stores/local.rb', line 24

def date
  @date
end

#rootObject (readonly)

Returns the value of attribute root.



24
25
26
# File 'lib/file_composer/stores/local.rb', line 24

def root
  @root
end

Instance Method Details

#move!(filename) ⇒ Object



33
34
35
36
37
38
# File 'lib/file_composer/stores/local.rb', line 33

def move!(filename)
  make_final_filename(filename).tap do |final_filename|
    ensure_directory_exists(final_filename)
    FileUtils.mv(filename, final_filename)
  end
end