Class: BuildMaster::Cotta

Inherits:
Object
  • Object
show all
Defined in:
lib/buildmaster/cotta/cotta.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system = PhysicalSystem.new) ⇒ Cotta

Returns a new instance of Cotta.



18
19
20
21
# File 'lib/buildmaster/cotta/cotta.rb', line 18

def initialize(system=PhysicalSystem.new)
  @system = system
  @command_interface = CommandInterface.new
end

Instance Attribute Details

#command_interfaceObject

Returns the value of attribute command_interface.



16
17
18
# File 'lib/buildmaster/cotta/cotta.rb', line 16

def command_interface
  @command_interface
end

Class Method Details

.dir(path) ⇒ Object

Creates a CottDirectory with the PhysicalSystem



61
62
63
64
# File 'lib/buildmaster/cotta/cotta.rb', line 61

def self::dir(path)
  return nil unless path
  return Cotta.new.dir(File.expand_path(path))
end

.file(path) ⇒ Object



72
73
74
75
# File 'lib/buildmaster/cotta/cotta.rb', line 72

def Cotta::file(path)
  return nil unless path
  return Cotta.new.file(File.expand_path(path))
end

.parent_dir(path) ⇒ Object



82
83
84
# File 'lib/buildmaster/cotta/cotta.rb', line 82

def Cotta::parent_dir(path)
  return Cotta.file(path).parent
end

.parent_of(path) ⇒ Object

DEPRECATED! Use parent_dir instead.



78
79
80
# File 'lib/buildmaster/cotta/cotta.rb', line 78

def Cotta::parent_of(path)
  return Cotta.file(path).parent
end

Instance Method Details

#dir(path) ⇒ Object



55
56
57
58
# File 'lib/buildmaster/cotta/cotta.rb', line 55

def dir(path)
  return nil unless path
  return CottaDir.new(@system, Pathname.new(path))
end

#entry(path) ⇒ Object

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



90
91
92
93
94
95
96
97
# File 'lib/buildmaster/cotta/cotta.rb', line 90

def entry(path)
  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_instance
end

#environment(variable, default = '') ⇒ Object



103
104
105
# File 'lib/buildmaster/cotta/cotta.rb', line 103

def environment(variable, default = '')
  @system.environment(variable, default)
end

#environment!(variable) ⇒ Object



99
100
101
# File 'lib/buildmaster/cotta/cotta.rb', line 99

def environment!(variable)
  @system.environment!(variable)
end

#file(path) ⇒ Object

Creates a CottaFile with the PhysicalSystem



67
68
69
70
# File 'lib/buildmaster/cotta/cotta.rb', line 67

def file(path)
  return nil unless path
  return CottaFile.new(@system, Pathname.new(path))
end

#pwdObject



28
29
30
# File 'lib/buildmaster/cotta/cotta.rb', line 28

def pwd
  dir(@system.pwd)
end

#shell(command_line, &block) ⇒ Object

Invoke the command line through the backing system



24
25
26
# File 'lib/buildmaster/cotta/cotta.rb', line 24

def shell(command_line, &block)
  @system.shell(command_line, &block)
end

#start(command_line) ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/buildmaster/cotta/cotta.rb', line 35

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