Module: HasModerated::CarrierWave

Defined in:
lib/has_moderated/carrier_wave.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
# File 'lib/has_moderated/carrier_wave.rb', line 6

def self.included(base)
  # lazy require so it doesn't require carrierwave until
  # it's actually used by the user
  require File.expand_path('../carrier_wave_patches', __FILE__)
  base.send :extend, ClassMethods
end

.photo_tmp_delete(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/has_moderated/carrier_wave.rb', line 13

def self.photo_tmp_delete(value)
  begin
    dirname = File.expand_path("..", value)
    filename = File.basename(value)
    # must delete versions as well, the filename of versions
    # should be version_filename.ext, where version is the name
    # of the version (e.g. thumb_test.png)
    r = Regexp.new("#{filename}\\Z")
    Dir.foreach(dirname) do |f|
      if f =~ r
        FileUtils.rm("#{dirname}/#{f}") # remove temp file
      end
    end
    FileUtils.rmdir(File.expand_path("..", value)) # will only remove folder if empty
  rescue
  end
end