Sha256: 687c15f2d79b2454d98609c3fb2747dd7dd17f483ef3bfac1ae38149820ae837

Contents?: true

Size: 705 Bytes

Versions: 4

Compression:

Stored size: 705 Bytes

Contents

module StorageRoom
  # Any file
  class File < Embedded
    key :filename
    key :content_type
    key :data
    key :remove
    
    class << self
      # Create a new File and set attributes from local file
      def new_with_filename(path)
        new.tap{|f| f.set_with_filename(path)}
      end
    end
    
    # Sets the filename, content_type and data attributes from a local filename so that a File can be uploaded through the API
    def set_with_filename(path)
      return if path.blank?
      
      self.filename = ::File.basename(path)
      self.content_type = ::MIME::Types.type_for(path).first.content_type
      self.data = ::Base64.encode64(::File.read(path))
    end
    

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
storage_room-0.3.5 lib/storage_room/embeddeds/file.rb
storage_room-0.3.4 lib/storage_room/embeddeds/file.rb
storage_room-0.3.3 lib/storage_room/embeddeds/file.rb
storage_room-0.3.2 lib/storage_room/embeddeds/file.rb