Class: Happi::File
- Inherits:
-
Object
- Object
- Happi::File
- Defined in:
- lib/happi/file.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#original_filename ⇒ Object
Returns the value of attribute original_filename.
Instance Method Summary collapse
- #encode_file ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(file) ⇒ File
constructor
A new instance of File.
- #multipart ⇒ Object
Constructor Details
#initialize(file) ⇒ File
Returns a new instance of File.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/happi/file.rb', line 10 def initialize(file) if file.is_a?(String) @mime_type = MIME::Types.type_for(file).first.content_type @file_name = file else @mime_type = file.content_type @file_name = file.path @original_filename = file.original_filename end end |
Instance Attribute Details
#file_name ⇒ Object
Returns the value of attribute file_name.
6 7 8 |
# File 'lib/happi/file.rb', line 6 def file_name @file_name end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
7 8 9 |
# File 'lib/happi/file.rb', line 7 def mime_type @mime_type end |
#original_filename ⇒ Object
Returns the value of attribute original_filename.
8 9 10 |
# File 'lib/happi/file.rb', line 8 def original_filename @original_filename end |
Instance Method Details
#encode_file ⇒ Object
29 30 31 |
# File 'lib/happi/file.rb', line 29 def encode_file Base64.encode64(File.read(file_name)) end |
#exists? ⇒ Boolean
21 22 23 |
# File 'lib/happi/file.rb', line 21 def exists? File.exist?(file_name) end |
#multipart ⇒ Object
25 26 27 |
# File 'lib/happi/file.rb', line 25 def multipart Faraday::UploadIO.new(file_name, mime_type, original_filename) if exists? end |