Sha256: 534f2db21434f7e07832e2e8a509e52c7bd6e30c63ebd1a084e6eb090488b177

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

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
        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
          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

10 entries across 10 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-2.0.12 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.11 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.10 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.9 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.8 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.7 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.6 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.5 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.4 lib/comfortable_mexican_sofa/seeds/file/exporter.rb
comfortable_mexican_sofa-2.0.3 lib/comfortable_mexican_sofa/seeds/file/exporter.rb