Class: Mongo::Model::AttachmentsHelper::FileHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/kit/models/attachments_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ FileHelper

Returns a new instance of FileHelper.



4
5
6
# File 'lib/kit/models/attachments_helper.rb', line 4

def initialize object
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



3
4
5
# File 'lib/kit/models/attachments_helper.rb', line 3

def object
  @object
end

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/kit/models/attachments_helper.rb', line 8

def file?
  object.is_a?(Hash) or object.is_a?(IO) or object.is_a?(Vfs::File)
end

#nameObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kit/models/attachments_helper.rb', line 12

def name
  if object.is_a?(Hash)
    object['filename'] || object[:filename]
  elsif object.is_a?(IO)
    File.basename(object.path)
  elsif object.is_a?(Vfs::File)
    object.name
  else
    object
  end
end