Class: Gluttonberg::GbFile

Inherits:
File
  • Object
show all
Defined in:
lib/gluttonberg/gb_file.rb

Overview

i made this class for providing extra methods in file class. I am using it for making assets from zip folder. keep in mind when we upload asset from browser, browser injects three extra attributes (that are given in MyFile class) but we are adding assets from file, i am injecting extra attributes manually. because asset library assumes that file has three extra attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



8
9
10
# File 'lib/gluttonberg/gb_file.rb', line 8

def content_type
  @content_type
end

#original_filenameObject

Returns the value of attribute original_filename.



8
9
10
# File 'lib/gluttonberg/gb_file.rb', line 8

def original_filename
  @original_filename
end

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/gluttonberg/gb_file.rb', line 8

def size
  @size
end

Class Method Details

.find_content_type(filename) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/gluttonberg/gb_file.rb', line 21

def self.find_content_type(filename)
  begin
   MIME::Types.type_for(filename).first.content_type
  rescue
    ""
  end
end

.init(filename) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/gluttonberg/gb_file.rb', line 10

def self.init(filename)
  file = self.new(filename)
  file.original_filename = filename
  file.content_type = find_content_type(filename)
  file.size = File.size(filename)
  file
end

Instance Method Details

#tempfileObject



18
19
20
# File 'lib/gluttonberg/gb_file.rb', line 18

def tempfile
  self
end