Class: CsvMapper::FileHandler
- Inherits:
-
Object
- Object
- CsvMapper::FileHandler
- Defined in:
- lib/csv_mapper/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.
5 6 7 |
# File 'lib/csv_mapper/file_handler.rb', line 5 def initialize() @path = File.join(Rails.root.to_s, "tmp") end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/csv_mapper/file_handler.rb', line 3 def filename @filename end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/csv_mapper/file_handler.rb', line 3 def path @path end |
Instance Method Details
#file_path ⇒ Object
24 25 26 |
# File 'lib/csv_mapper/file_handler.rb', line 24 def file_path File.join(@path, @filename) end |
#load_file(filename) ⇒ Object
15 16 17 18 |
# File 'lib/csv_mapper/file_handler.rb', line 15 def load_file(filename) @filename = filename File.exist?(file_path) end |
#remove_file ⇒ Object
20 21 22 |
# File 'lib/csv_mapper/file_handler.rb', line 20 def remove_file File.delete(file_path) end |
#save_temp_file(tempfile) ⇒ Object
9 10 11 12 13 |
# File 'lib/csv_mapper/file_handler.rb', line 9 def save_temp_file(tempfile) @filename = unique_filename FileUtils.copy_file(tempfile.path, file_path) File.exists?(file_path) end |
#unique_filename ⇒ Object
28 29 30 31 |
# File 'lib/csv_mapper/file_handler.rb', line 28 def unique_filename t = Time.now.strftime("%Y%m%d") "#{t}-#{$$}-#{rand(0x100000000000000).to_s(36)}" end |