module Spectra::Serializable
Attributes
directory[RW]
filename[RW]
Public Instance Methods
destination(attributes)
click to toggle source
# File lib/spectra/views/serializable.rb, line 32 def destination(attributes) destination = self.directory destination << '/' unless destination.end_with?('/') destination + self.filename end
serialize(attributes)
click to toggle source
# File lib/spectra/views/serializable.rb, line 8 def serialize(attributes) text = self.render(attributes) path = self.destination(attributes) begin file = File.open(path, 'w+') rescue Exception raise Informative, "Couldn't open #{path}" else self.write_file(file, text, path) ensure file.close unless file.nil? end end
write_file(file, text, path)
click to toggle source
# File lib/spectra/views/serializable.rb, line 23 def write_file(file, text, path) Spectra.logger.info "[✓] Generating #{path}" if Config.dry_run Spectra.logger.info "\n#{text.chomp}" else file.write(text) end end