Class: MyFile

Inherits:
File
  • Object
show all
Defined in:
app/controllers/gluttonberg/admin/asset_library/assets_controller.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

- (Object) content_type

Returns the value of attribute content_type



307
308
309
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 307

def content_type
  @content_type
end

- (Object) original_filename

Returns the value of attribute original_filename



307
308
309
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 307

def original_filename
  @original_filename
end

- (Object) size

Returns the value of attribute size



307
308
309
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 307

def size
  @size
end

Class Method Details

+ (Object) find_content_type(filename)



320
321
322
323
324
325
326
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 320

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

+ (Object) init(filename, entry)



309
310
311
312
313
314
315
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 309

def self.init(filename , entry)
  file = MyFile.new(filename) 
  file.original_filename = filename
  file.content_type = find_content_type(filename)
  file.size = entry.size
  file
end

Instance Method Details

- (Object) tempfile



317
318
319
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 317

def tempfile
  self
end