Class: FileComposer::Stores::Local
- Inherits:
-
Object
- Object
- FileComposer::Stores::Local
- 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
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(date: Time.now.utc.to_date, root: '') ⇒ Local
constructor
A new instance of Local.
- #move!(filename) ⇒ Object
Constructor Details
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
24 25 26 |
# File 'lib/file_composer/stores/local.rb', line 24 def date @date end |
#root ⇒ Object (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 |