lib/buildmaster/cotta/cotta.rb in BuildMaster-1.1.9 vs lib/buildmaster/cotta/cotta.rb in BuildMaster-1.1.12

- old
+ new

@@ -1,27 +1,51 @@ -$:.unshift File.dirname(__FILE__) +dir = File.dirname(__FILE__) -require 'physical_system' -require 'cotta_dir' -require 'cotta_file' require 'pathname' -require 'cotta_pathname' -require 'command_interface' +require dir + '/physical_system' +require dir + '/io_chain' +require dir + '/cotta_dir' +require dir + '/cotta_file' +require dir + '/cotta_pathname' +require dir + '/command_interface' module BuildMaster + +# The file factory of Cotta files that handles creation of the CottaFile and CottaDirectory +# instances. This class also can be used to start command lines class Cotta attr_accessor :command_interface def initialize(system=PhysicalSystem.new) @system = system @command_interface = CommandInterface.new end + # Invoke the command line through the backing system def shell(command_line, &block) @system.shell(command_line, &block) end + def pwd + dir(@system.pwd) + end + + # Starts the process. Unlike shell method, this method does not + # collect the output, thus suitable for starting a server in Ruby + # and leave it running for a long time + def start(command_line) + @system.shell(command_line) do |io| + if (block_given?) + yield io + else + while (line = io.gets) + puts line + end + end + end + end + def command_interface=(value) if (value) @command_interface = value else @command_interface = CommandInterface.new @@ -31,15 +55,17 @@ def dir(path) return nil unless path return CottaDir.new(@system, Pathname.new(path)) end - def Cotta::dir(path) + # Creates a CottDirectory with the PhysicalSystem + def self::dir(path) return nil unless path return Cotta.new.dir(File.expand_path(path)) end + # Creates a CottaFile with the PhysicalSystem def file(path) return nil unless path return CottaFile.new(@system, Pathname.new(path)) end @@ -55,16 +81,20 @@ def Cotta::parent_dir(path) return Cotta.file(path).parent end + # Creates the entry given a path. This will return either + # CottaFile or CottaDirectory depending by checking the path + # passed in, which means that if neither a directory nor a file + # exists with this name it will raise an error def entry(path) - entry = file(path) - unless (entry.exists?) - entry = dir(path) - raise "#{path} exists as niether file nor directory" unless entry.exists? + entry_instance = file(path) + unless (entry_instance.exists?) + entry_instance = dir(path) + raise "#{path} exists as niether file nor directory" unless entry_instance.exists? end - return entry + return entry_instance end def environment!(variable) @system.environment!(variable) end \ No newline at end of file