class ComfortableMexicanSofa::Seeds::Exporter

Attributes

from[RW]
path[RW]
site[RW]
to[RW]

Public Class Methods

new(from, to = from) click to toggle source
# File lib/comfortable_mexican_sofa/seeds.rb, line 79
def initialize(from, to = from)
  self.from = from
  self.to   = to
  self.site = Comfy::Cms::Site.where(identifier: from).first!
end

Public Instance Methods

export!(classes = nil) click to toggle source

if passed nil will use default seed classes

# File lib/comfortable_mexican_sofa/seeds.rb, line 86
def export!(classes = nil)
  classes ||= SEED_CLASSES
  classes.each do |klass|
    klass = "ComfortableMexicanSofa::Seeds::#{klass}::Exporter"
    klass.constantize.new(from, to).export!
  end
end

Private Instance Methods

prepare_folder!(path) click to toggle source
# File lib/comfortable_mexican_sofa/seeds.rb, line 107
def prepare_folder!(path)
  FileUtils.rm_rf(path)
  FileUtils.mkdir_p(path)
end
write_file_content(path, data) click to toggle source

Writing to the seed file. Takes in file handler and array of hashes with `header` and `content` keys

# File lib/comfortable_mexican_sofa/seeds.rb, line 98
def write_file_content(path, data)
  ::File.open(::File.join(path), "wb") do |f|
    data.each do |item|
      f.write("[#{item[:header]}]\n")
      f.write("#{item[:content]}\n")
    end
  end
end