Class: Writefully::Tools::Eraser
Instance Attribute Summary
Attributes inherited from Stationery
#asset, #content, #index, #site_id
Instance Method Summary
collapse
Methods inherited from Stationery
#initialize, #perform
Instance Method Details
#destroy ⇒ Object
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
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_assets ⇒ Object
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
|
#trash ⇒ Object
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
|
#use ⇒ Object
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
|