Class: Writefully::Tools::Eraser

Inherits:
Stationery show all
Defined in:
lib/writefully/tools/eraser.rb

Instance Attribute Summary

Attributes inherited from Stationery

#asset, #content, #index, #site_id

Instance Method Summary collapse

Methods inherited from Stationery

#initialize, #perform

Constructor Details

This class inherits a constructor from Writefully::Tools::Stationery

Instance Method Details

#destroyObject



26
27
28
# File 'lib/writefully/tools/eraser.rb', line 26

def destroy
  compute_type.by_site(site_id).where(slug: content.slug).first.destroy
end

#directory_exists?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/writefully/tools/eraser.rb', line 30

def directory_exists?
  File.directory?(File.join(Writefully.options[:content], 
                            index[:site], index[:resource], index[:slug]))
end

#remove_assetsObject



18
19
20
21
22
23
24
# File 'lib/writefully/tools/eraser.rb', line 18

def remove_assets
  Writefully::Storage.directory.files.map do |file| 
    file.key if file.key.match(::Regexp.new(index[:slug])) 
  end.compact.each do |key|
    Celluloid::Actor[:pigeons].future.remove(key)
  end
end

#trashObject



12
13
14
15
16
# File 'lib/writefully/tools/eraser.rb', line 12

def trash
  compute_type.by_site(site_id)
                .where(slug: content.slug)
                  .first.update_attributes(trashed: true)
end

#useObject



5
6
7
8
9
10
# File 'lib/writefully/tools/eraser.rb', line 5

def use
  trash 
  remove_assets
  destroyed = future.destroy
  terminate if destroyed.value
end