Sha256: 9e289fec7bfe068e40b8a32e69763d205305f4cf31a72603ab807ae24b3ec7e3

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

module Writefully
  module Tools
    class Pencil < Stationery

      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

      def computed_attributes
        content.meta.merge({ 
          "content" => asset.convert_for(content.body),
          "details" => asset.convert_for(content.details),
          "trashed" => false
        })
      end

      def write
        compute_type.by_site(site_id).where(slug: content.slug)
                      .first_or_initialize
                        .update_attributes(computed_attributes)
      end
      
      def upload_assets
        asset.names.map do |name|
          Celluloid::Actor[:pigeons].future.upload(asset.endpoint, asset.path, name)
        end
      end

      def can_update_db? uploaded
        if asset.names.count == uploaded.count
          true
        else 
          raise SomeAssetsNotUploaded, "Some assets was not uploaded"
        end
      end
      
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
writefully-0.8.2 lib/writefully/tools/pencil.rb
writefully-0.8.1 lib/writefully/tools/pencil.rb
writefully-0.8.0 lib/writefully/tools/pencil.rb
writefully-0.7.1 lib/writefully/tools/pencil.rb
writefully-0.6.12 lib/writefully/tools/pencil.rb
writefully-0.6.11 lib/writefully/tools/pencil.rb
writefully-0.6.10 lib/writefully/tools/pencil.rb
writefully-0.6.9 lib/writefully/tools/pencil.rb
writefully-0.6.7 lib/writefully/tools/pencil.rb
writefully-0.6.6 lib/writefully/tools/pencil.rb
writefully-0.6.5 lib/writefully/tools/pencil.rb
writefully-0.6.4 lib/writefully/tools/pencil.rb
writefully-0.6.3 lib/writefully/tools/pencil.rb
writefully-0.6.2 lib/writefully/tools/pencil.rb
writefully-0.5.1 lib/writefully/tools/pencil.rb
writefully-0.5.0 lib/writefully/tools/pencil.rb