Class: Shutterbug::Storage::FileStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/shutterbug/storage/file_storage.rb

Constant Summary collapse

MIME_TYPES =
{
  '.png'  => 'image/png',
  '.jpeg' => 'image/jpeg',
  '.jpg'  => 'image/jpeg',
  '.html' => 'text/html',
  ''      => 'text/html'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileStorage

Returns a new instance of FileStorage.



19
20
21
22
# File 'lib/shutterbug/storage/file_storage.rb', line 19

def initialize(filename)
  @filename = Configuration.instance.fs_path_for(filename)
  @url = self.class.get_url(filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/shutterbug/storage/file_storage.rb', line 4

def filename
  @filename
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/shutterbug/storage/file_storage.rb', line 5

def url
  @url
end

Class Method Details

.get_url(name) ⇒ Object



15
16
17
# File 'lib/shutterbug/storage/file_storage.rb', line 15

def self.get_url(name)
  "#{Handlers::FileHandler.uri_prefix}/#{name}"
end

Instance Method Details

#get_contentObject



24
25
26
# File 'lib/shutterbug/storage/file_storage.rb', line 24

def get_content
  File.open(@filename, 'r')
end

#mime_typeObject



28
29
30
# File 'lib/shutterbug/storage/file_storage.rb', line 28

def mime_type
  MIME_TYPES[File.extname(@filename)]
end