Class: Roart::Attachment
- Inherits:
-
File
- Object
- File
- Roart::Attachment
- Defined in:
- lib/roart/attachment.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, file) ⇒ Attachment
constructor
A new instance of Attachment.
- #mime_type ⇒ Object
- #path ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(name, file) ⇒ Attachment
Returns a new instance of Attachment.
17 18 19 20 |
# File 'lib/roart/attachment.rb', line 17 def initialize(name, file) @name = name @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/roart/attachment.rb', line 15 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/roart/attachment.rb', line 15 def name @name end |
Class Method Details
.detect(*args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/roart/attachment.rb', line 34 def self.detect(*args) AttachmentCollection.new Array(args.compact).flatten.map { |file| if file.is_a?(File) Attachment.new(File.basename(file.path), file) elsif file.is_a?(String) Attachment.new(File.basename(file), File.open(file, 'rb')) elsif file.respond_to?(:open, :original_filename) Attachment.new(file.original_filename, file.open) end }.compact end |
Instance Method Details
#mime_type ⇒ Object
30 31 32 |
# File 'lib/roart/attachment.rb', line 30 def mime_type file.content_type if file.respond_to?(:content_type) end |
#path ⇒ Object
22 23 24 |
# File 'lib/roart/attachment.rb', line 22 def path name end |
#read ⇒ Object
26 27 28 |
# File 'lib/roart/attachment.rb', line 26 def read file.read end |