Class: Writefully::Tools::Pencil
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
#can_update_db?(uploaded) ⇒ Boolean
31
32
33
34
35
36
37
|
# File 'lib/writefully/tools/pencil.rb', line 31
def can_update_db? uploaded
if asset.names.count == uploaded.count
true
else
raise SomeAssetsNotUploaded, "Some assets was not uploaded"
end
end
|
#computed_attributes ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/writefully/tools/pencil.rb', line 11
def computed_attributes
content.meta.merge({
"content" => asset.convert_for(content.body),
"details" => asset.convert_for(content.details),
"trashed" => false
})
end
|
#upload_assets ⇒ Object
25
26
27
28
29
|
# File 'lib/writefully/tools/pencil.rb', line 25
def upload_assets
asset.names.map do |name|
Celluloid::Actor[:pigeons].future.upload(asset.endpoint, asset.path, name)
end
end
|
#use ⇒ Object
5
6
7
8
9
|
# File 'lib/writefully/tools/pencil.rb', line 5
def use
assets_uploaded = upload_assets.map(&:value).compact
written_to_db = future.write if can_update_db?(assets_uploaded)
terminate if written_to_db.value
end
|
#write ⇒ Object
19
20
21
22
23
|
# File 'lib/writefully/tools/pencil.rb', line 19
def write
compute_type.by_site(site_id).where(slug: content.slug)
.first_or_initialize
.update_attributes(computed_attributes)
end
|