Class: CarrierWave::Workers::StoreAsset

Inherits:
Struct
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/backgrounder/workers/store_asset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



5
6
7
# File 'lib/backgrounder/workers/store_asset.rb', line 5

def column
  @column
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/backgrounder/workers/store_asset.rb', line 5

def id
  @id
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



5
6
7
# File 'lib/backgrounder/workers/store_asset.rb', line 5

def klass
  @klass
end

Class Method Details

.perform(*args) ⇒ Object



9
10
11
# File 'lib/backgrounder/workers/store_asset.rb', line 9

def self.perform(*args)
  new(*args).perform
end

Instance Method Details

#perform(*args) ⇒ Object



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

def perform(*args)
  set_args(*args) unless args.empty?
  resource = klass.is_a?(String) ? klass.constantize : klass
  record = resource.find id
  if tmp = record.send(:"#{column}_tmp")
    asset = record.send(:"#{column}")
    cache_dir  = [asset.root, asset.cache_dir].join("/")
    cache_path = [cache_dir, tmp].join("/")
    tmp_dir = [cache_dir, tmp.split("/")[0]].join("/")
    record.send :"process_#{column}_upload=", true
    record.send :"#{column}_tmp=", nil
    File.open(cache_path) { |f| record.send :"#{column}=", f }
    if record.save!
      FileUtils.rm_r(tmp_dir, :force => true)
    end
  end
end

#set_args(klass, id, column) ⇒ Object



31
32
33
# File 'lib/backgrounder/workers/store_asset.rb', line 31

def set_args(klass, id, column)
  self.klass, self.id, self.column = klass, id, column
end