Class: BuildMaster::Cotta
- Inherits:
-
Object
- Object
- BuildMaster::Cotta
- 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
-
#command_interface ⇒ Object
Returns the value of attribute command_interface.
Class Method Summary collapse
-
.dir(path) ⇒ Object
Creates a CottDirectory with the PhysicalSystem.
- .file(path) ⇒ Object
- .parent_dir(path) ⇒ Object
-
.parent_of(path) ⇒ Object
DEPRECATED! Use
parent_dir
instead.
Instance Method Summary collapse
- #dir(path) ⇒ Object
-
#entry(path) ⇒ Object
Creates the entry given a path.
- #environment(variable, default = '') ⇒ Object
- #environment!(variable) ⇒ Object
-
#file(path) ⇒ Object
Creates a CottaFile with the PhysicalSystem.
-
#initialize(system = PhysicalSystem.new) ⇒ Cotta
constructor
A new instance of Cotta.
- #pwd ⇒ Object
-
#shell(command_line, &block) ⇒ Object
Invoke the command line through the backing system.
-
#start(command_line) ⇒ Object
Starts the process.
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_interface ⇒ Object
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.(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.(path)) 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 |
#pwd ⇒ Object
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 |