Module: Paperclip::Storage::Eitheror

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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



64
65
66
# File 'lib/paperclip/storage/eitheror.rb', line 64

def method_missing method, *args
  usable_storage.send(method, *args)
end

Class Method Details

.extended(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/paperclip/storage/eitheror.rb', line 4

def self.extended(base)
  base.instance_eval do
    base.options[:either][:enabled] = true if base.options[:either][:enabled].nil?
    @either = Attachment.new(base.name, base.instance, base.options.merge(base.options[:either]))
    @or = Attachment.new(base.name, base.instance, base.options.merge(base.options[:or]))

    define_aliases @either, base.options[:either].fetch(:alias, {})
    define_aliases @or, base.options[:or].fetch(:alias, {})
  end
end

Instance Method Details

#either_enabled?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/paperclip/storage/eitheror.rb', line 68

def either_enabled?
  callable_option(@either, :enabled)
end

#flush_deletesObject



44
45
46
47
48
49
50
51
# File 'lib/paperclip/storage/eitheror.rb', line 44

def flush_deletes
  all_storages.each do |storage|
    storage.instance_variable_set(:@queued_for_delete, @queued_for_delete)
    storage.flush_deletes
  end

  @queued_for_delete = []
end

#flush_writesObject



36
37
38
39
40
41
42
# File 'lib/paperclip/storage/eitheror.rb', line 36

def flush_writes
  storage = usable_storage
  storage.instance_variable_set(:@queued_for_write, @queued_for_write)
  storage.flush_writes

  @queued_for_write = {}
end

#path(style_name = default_style) ⇒ Object



28
29
30
# File 'lib/paperclip/storage/eitheror.rb', line 28

def path(style_name = default_style)
  usable_storage.path(style_name)
end

#queue_all_for_deleteObject



59
60
61
62
# File 'lib/paperclip/storage/eitheror.rb', line 59

def queue_all_for_delete
  queue_some_for_delete([:original, *styles.keys].uniq)
  super
end

#queue_some_for_delete(*styles) ⇒ Object



53
54
55
56
57
# File 'lib/paperclip/storage/eitheror.rb', line 53

def queue_some_for_delete(*styles)
  @queued_for_delete += styles.flatten.uniq.map do |style|
    all_storages.map { |s| s.path(style) if s.exists?(style) }
  end.flatten.compact
end

#syncObject



15
16
17
18
# File 'lib/paperclip/storage/eitheror.rb', line 15

def sync
  @either.assign @or
  @either.save
end

#syncable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/paperclip/storage/eitheror.rb', line 24

def syncable?
  @or.exists?
end

#synced?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/paperclip/storage/eitheror.rb', line 20

def synced?
  @either.exists?
end

#url(style_name = default_style, options = {}) ⇒ Object



32
33
34
# File 'lib/paperclip/storage/eitheror.rb', line 32

def url(style_name = default_style, options = {})
  usable_storage.url(style_name, options)
end