Sha256: 3e5b867ace8db94a8eea473d430ac1c3a43bf1bed1be9f340b2d3ef97263919d

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 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)
          Occams.logger.info("[CMS SEEDS] Exported File \t #{file.attachment.filename}")
        rescue Errno::ENOENT, OpenURI::HTTPError
          Occams.logger.warn("[CMS SEEDS] No physical File \t #{file.attachment.filename}")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
occams-1.1.0 lib/occams/seeds/file/exporter.rb
occams-1.0.8 lib/occams/seeds/file/exporter.rb
occams-1.0.7.3 lib/occams/seeds/file/exporter.rb
occams-1.0.7.2 lib/occams/seeds/file/exporter.rb