Class: StorageRoom::Image

Inherits:
File show all
Defined in:
lib/storage_room/embeddeds/image.rb

Overview

An Image with optional thumbnails

Instance Method Summary collapse

Methods inherited from File

#file_type, new_with_filename, #set_with_filename

Methods included from Accessors

#[], #as_json, #attributes, #attributes=, #eql?, #hash, #initialize, #inspect, #loaded?, #proxy?, #reset!, #response_data, #response_data=, #set_from_response_data, #to_hash

Instance Method Details

#download_to_directory(path) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/storage_room/embeddeds/image.rb', line 31

def download_to_directory(path)
  super
  
  version_identifiers.each do |version|
    download_file(self.url(version), ::File.join(path, local_filename(version)))
  end
  true
end

#local_filename(name = nil) ⇒ Object



27
28
29
# File 'lib/storage_room/embeddeds/image.rb', line 27

def local_filename(name = nil)
  localize_filename(url(name))
end

#processing?Boolean

Are versions of the Image still being processed on the server?

Returns:

  • (Boolean)


23
24
25
# File 'lib/storage_room/embeddeds/image.rb', line 23

def processing?
  self[:@processing]
end

#url(name = nil) ⇒ Object

Returns the URL of an Image or the URL of a version if a string or symbol is passed



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/storage_room/embeddeds/image.rb', line 10

def url(name = nil)
  if name
    if version_identifiers.include?(name.to_s)
      self[:@versions][name.to_s][:@url]
    else
      raise "Invalid Image Version identifier: '#{name}' (must be #{version_identifiers.join(', ')})"
    end
  else
    self[:@url]
  end
end

#version_identifiersObject

Returns all valid ImageVersion identifiers for this Image



5
6
7
# File 'lib/storage_room/embeddeds/image.rb', line 5

def version_identifiers
  self[:@versions].keys
end