Module: Paperclip::Storage::Atompub

Defined in:
lib/paperclip/storage/atompub.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/paperclip/storage/atompub.rb', line 6

def self.extended(base)
  base.instance_eval do
    (@options.delete(:atompub_config) || {}).each do |key, value|
      @options[:"atompub_#{key}"] = value
    end
  end
end

Instance Method Details

#exists?(style_name = default_style) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/paperclip/storage/atompub.rb', line 23

def exists?(style_name = default_style)
  if original_filename
    ! atompub_entry(style_name).nil?
  else
    false
  end
end

#flush_deletesObject

:nodoc:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/paperclip/storage/atompub.rb', line 45

def flush_deletes #:nodoc:
  @queued_for_delete.each do |path|
    begin
      log("deleting #{path}")
      entry = atompub_entry(path)
      attachment = atompub_attachment(path).destroy
      attachment.destroy
      atompub_client.delete_media(entry.edit_media_link)
    rescue ::Atompub::RequestError
      # Ignore this.
    end
  end
  @queued_for_delete = []
end

#flush_writesObject

:nodoc:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paperclip/storage/atompub.rb', line 31

def flush_writes #:nodoc:
  @queued_for_write.each do |style, file|
    begin
      log("saving #{path(style)}")
      attachment = atompub_attachment(style)
      attachment.resource_uri = atompub_client.create_media(options[:atompub_media_collection_uri], file.path, file.content_type, original_filename)
      attachment.content_src = atompub_client.get_entry(attachment.resource_uri).content.src
      attachment.save!
    ensure
      file.rewind
    end
  end
end

#path(style_name = default_style) ⇒ Object



14
15
16
# File 'lib/paperclip/storage/atompub.rb', line 14

def path(style_name = default_style)
  style_name
end

#url(style_name = default_style) ⇒ Object



18
19
20
21
# File 'lib/paperclip/storage/atompub.rb', line 18

def url(style_name = default_style)
  attachment = atompub_attachment(style_name)
  attachment ? attachment.content_src : nil
end