class Writefully::Tools::Pencil

Public Instance Methods

can_update_db?(uploaded) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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