Class: Grip::Attachment
- Inherits:
-
Object
- Object
- Grip::Attachment
- Includes:
- MongoMapper::Document
- Defined in:
- lib/grip/attachment.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_method(method_name, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/grip/attachment.rb', line 43 def self.create_method method_name, &block define_method(method_name) do |*args| yield *args end end |
Instance Method Details
#file ⇒ Object
35 36 37 |
# File 'lib/grip/attachment.rb', line 35 def file read_from_grid grid_key end |
#file=(new_file) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/grip/attachment.rb', line 25 def file=new_file raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile)) self.file_name = new_file.is_a?(Tempfile) ? new_file.original_filename : File.basename(new_file.path) self.file_size = File.size(new_file.path) self.content_type = MIME::Types.type_for(new_file.path) write_to_grid self, new_file end |
#grid_key ⇒ Object
39 40 41 |
# File 'lib/grip/attachment.rb', line 39 def grid_key "#{owner_type.pluralize}/#{owner_id}/#{name}/#{file_name}".downcase end |