Sha256: 644d6974319c81039ecb9167d13c0f45de578aef5d38a93bbc02226556ff9717

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module ComfortableMexicanSofa::Seeds::File
  class Exporter < ComfortableMexicanSofa::Seeds::Exporter

    def initialize(from, to = from)
      super
      self.path = ::File.join(ComfortableMexicanSofa.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}"
          ComfortableMexicanSofa.logger.warn(message)
          next
        end

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

  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
PixelForce_ETS-0.0.2 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
PixelForce_ETS-0.0.1 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest2-0.0.4 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest2-0.0.3 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest2-0.0.2 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest2-0.0.1 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest-0.0.1 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcyEtsTest-2.2.19 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
ComfortableMexicanSofa-2.0.18 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
kcy1-1.0 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.18 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.17 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.16 lib/comfortable_mexican_sofa/seeds/file/exporter.rb