class Epubber::Services::Persistance
Attributes
workspace[R]
Public Class Methods
new(workspace)
click to toggle source
# File lib/epubber/services/persistance.rb, line 4 def initialize(workspace) @workspace = workspace end
Public Instance Methods
clean()
click to toggle source
Remove the working directory, thus cleaning the file system
# File lib/epubber/services/persistance.rb, line 16 def clean FileUtils.remove_dir workspace, true end
persist(file:, content:)
click to toggle source
Persist a file into the working directory with the spcified contents. The file argument is the relative path to the new file, eg: test/chapters/file.xhtml
# File lib/epubber/services/persistance.rb, line 10 def persist(file:, content:) create_path_for file write file, content end
Protected Instance Methods
create_path_for(file)
click to toggle source
# File lib/epubber/services/persistance.rb, line 30 def create_path_for(file) dir = File.dirname path(file) FileUtils.mkdir_p dir unless File.directory?(dir) end
path(file)
click to toggle source
# File lib/epubber/services/persistance.rb, line 35 def path(file) File.join workspace, file end
write(file, content)
click to toggle source
# File lib/epubber/services/persistance.rb, line 22 def write(file, content) if content.is_a?(File) FileUtils.cp content.path, File.dirname(path(file)) else File.write path(file), content end end