Class: Gluttonberg::MyFile2

Inherits:
File
  • Object
show all
Defined in:
app/models/gluttonberg/asset.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 Attribute Details

#content_typeObject

Returns the value of attribute content_type.



184
185
186
# File 'app/models/gluttonberg/asset.rb', line 184

def content_type
  @content_type
end

#original_filenameObject

Returns the value of attribute original_filename.



184
185
186
# File 'app/models/gluttonberg/asset.rb', line 184

def original_filename
  @original_filename
end

#sizeObject

Returns the value of attribute size.



184
185
186
# File 'app/models/gluttonberg/asset.rb', line 184

def size
  @size
end

Class Method Details

.find_content_type(filename) ⇒ Object



194
195
196
197
198
199
200
# File 'app/models/gluttonberg/asset.rb', line 194

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

.init(filename) ⇒ Object



186
187
188
189
190
191
192
# File 'app/models/gluttonberg/asset.rb', line 186

def self.init(filename)
  file = MyFile2.new(Rails.root+"/bulks/" + filename)
  file.original_filename = filename
  file.content_type = find_content_type(filename)
  file.size = File.size(Rails.root+"/bulks/" + filename)
  file
end