Sha256: ba4742bed06661704895e483c93c34822cd5556a25ba7fa6ad13ef76ea9b2585

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 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.write(::File.join(path, "_#{file.attachment.filename}.yml"), {
          'label' => file.label,
          'description' => file.description,
          'categories' => file.categories.map(&:label)
        }.to_yaml)

        # writing content
        begin
          ::File.binwrite(::File.join(path, ::File.basename(file_path)), file.attachment.download)
        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

8 entries across 8 versions & 1 rubygems

Version Path
occams-1.0.7.1 lib/occams/seeds/file/exporter.rb
occams-1.0.7 lib/occams/seeds/file/exporter.rb
occams-1.0.6.1 lib/occams/seeds/file/exporter.rb
occams-1.0.6 lib/occams/seeds/file/exporter.rb
occams-1.0.5 lib/occams/seeds/file/exporter.rb
occams-1.0.4 lib/occams/seeds/file/exporter.rb
occams-1.0.3 lib/occams/seeds/file/exporter.rb
occams-1.0.2 lib/occams/seeds/file/exporter.rb