Sha256: ddf6277439d57c9b8cb022e91b58e2615a961dc201ca48cc1cf6e93ed6a6bb67

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Occams::Seeds::File
  class Exporter < Occams::Seeds::Exporter

    def initialize(from, to = from)
      super
      self.path = ::File.join(Occams.config.seeds_path, to, "files/")
    end

    def export!
      prepare_folder!(path)

      site.files.each do |file|
        file_path = File.join(path, file.attachment.filename.to_s)

        # writing attributes
        ::File.open(::File.join(path, "_#{file.attachment.filename}.yml"), "w") do |f|
          f.write({
            "label"       => file.label,
            "description" => file.description,
            "categories"  => file.categories.map(&:label)
          }.to_yaml)
        end

        # writing content
        begin
          ::File.open(::File.join(path, ::File.basename(file_path)), "wb") do |f|
            f.write(file.attachment.download)
          end
        rescue Errno::ENOENT, OpenURI::HTTPError
          message = "[CMS SEEDS] No physical File \t #{file.attachment.filename}"
          Occams.logger.warn(message)
          next
        end

        message = "[CMS SEEDS] Exported File \t #{file.attachment.filename}"
        Occams.logger.info(message)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
occams-1.0.0 lib/occams/seeds/file/exporter.rb