Creation
All cotta file and directory creations are done through BuildMaster::Cotta.
require 'buildmaster/cotta' # Creat through the factory class instance Cotta cotta = BuildMaster::Cotta.new file = cotta.file('directory/subdirectory/file.txt') dir = cotta.dir('directory/site') # Create through the static factory methods on Cotta file = BuildMaster::Cotta.file('/tmp/output/file.html') dir_of_current_file = BuildMaster::Cotta.parent_of(__FILE__) # Create through existing file and directory objects dir = file.parent file = dir.file('path/to/file.txt')
File and Directory operations
The file and directory objects has the methods for the opertions that apply to them.
# load and save file.save("* first item\n") # save a content file.load # => 'first item\n' # read and write with optional closure file.append {|io| io.puts '* second item'} # appends to the end of file file.read {|io| io.gets} # => 'first item\n' root.dir('src').copy_to(root.dir('build/docs/source')) root.dir('build/docs').archive.zip # => resuling tar zip file build/docs.tar.zip
Test
The BuildMaster::Cotta is backed by a file system. By default, it is BuildMaster::PhysicalSystem.
For testing purpose, you can create Cotta objects using BuildMaster::InMemorySystem and inject them
into the class that you are trying to test.
require 'buildmaster/cotta/in_memory_system' require 'buildmaster/project' cotta = BuildMaster::Cotta.new(BuildMaster::InMemorySystem.new) file = cotta.file('/root/file.txt') file.write {|io| io.puts '1.2.1'} BuildMaster::VersionNumberFile.new(file).version_number.should == '1.2.1'