Class: ComfortableMexicanSofa::Seeds::File::Exporter
- Defined in:
- lib/comfortable_mexican_sofa/seeds/file/exporter.rb
Instance Attribute Summary
Attributes inherited from Exporter
Instance Method Summary collapse
- #export! ⇒ Object
-
#initialize(from, to = from) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(from, to = from) ⇒ Exporter
Returns a new instance of Exporter.
6 7 8 9 |
# File 'lib/comfortable_mexican_sofa/seeds/file/exporter.rb', line 6 def initialize(from, to = from) super self.path = ::File.join(ComfortableMexicanSofa.config.seeds_path, to, "files/") end |
Instance Method Details
#export! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/comfortable_mexican_sofa/seeds/file/exporter.rb', line 11 def export! prepare_folder!(path) site.files.each do |file| file_path = File.join(path, file..filename.to_s) # writing attributes ::File.open(::File.join(path, "_#{file..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..download) end rescue Errno::ENOENT, OpenURI::HTTPError = "[CMS SEEDS] No physical File \t #{file..filename}" ComfortableMexicanSofa.logger.warn() next end = "[CMS SEEDS] Exported File \t #{file..filename}" ComfortableMexicanSofa.logger.info() end end |