Class: CSVMagic::FileHandler
- Inherits:
-
Object
- Object
- CSVMagic::FileHandler
- Defined in:
- lib/csv_magic/file_handler.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #file_path ⇒ Object
-
#initialize ⇒ FileHandler
constructor
A new instance of FileHandler.
- #load_file(filename) ⇒ Object
- #remove_file ⇒ Object
- #save_temp_file(tempfile) ⇒ Object
- #unique_filename ⇒ Object
Constructor Details
#initialize ⇒ FileHandler
Returns a new instance of FileHandler.
6 7 8 |
# File 'lib/csv_magic/file_handler.rb', line 6 def initialize() @path = ::File.join(::Rails.root.to_s, "tmp") end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/csv_magic/file_handler.rb', line 4 def filename @filename end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/csv_magic/file_handler.rb', line 4 def path @path end |
Instance Method Details
#file_path ⇒ Object
25 26 27 |
# File 'lib/csv_magic/file_handler.rb', line 25 def file_path ::File.join(@path, @filename) end |
#load_file(filename) ⇒ Object
16 17 18 19 |
# File 'lib/csv_magic/file_handler.rb', line 16 def load_file(filename) @filename = filename ::File.exist?(file_path) end |
#remove_file ⇒ Object
21 22 23 |
# File 'lib/csv_magic/file_handler.rb', line 21 def remove_file ::File.delete(file_path) end |
#save_temp_file(tempfile) ⇒ Object
10 11 12 13 14 |
# File 'lib/csv_magic/file_handler.rb', line 10 def save_temp_file(tempfile) @filename = unique_filename ::FileUtils.copy_file(tempfile.path, file_path) ::File.exists?(file_path) end |
#unique_filename ⇒ Object
29 30 31 32 |
# File 'lib/csv_magic/file_handler.rb', line 29 def unique_filename t = ::Time.now.strftime("%Y%m%d") "#{t}-#{$$}-#{rand(0x100000000000000).to_s(36)}" end |