Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/libcfruby/cfrubyscript.rb

Overview

Including cfrubyscript adds a number of new helper methods to String that are useful in cutting down the verbosity of system administration scripts.

Instance Method Summary collapse

Instance Method Details

#chmod(mode, options = {}) ⇒ Object

Calls Cfruby::FileOps.chmod on the file named in the String



78
79
80
# File 'lib/libcfruby/cfrubyscript.rb', line 78

def chmod(mode, options = {})
	Cfruby::FileOps.chmod(self, mode, options)
end

#chown(owner = Process::Sys.geteuid(), group = Process::Sys.getegid(), options = {}) ⇒ Object

Calls Cfruby::FileOps.chown on the file named in the String



72
73
74
# File 'lib/libcfruby/cfrubyscript.rb', line 72

def chown(owner = Process::Sys.geteuid(), group = Process::Sys.getegid(), options = {})
	Cfruby::FileOps.chown(self, owner, group, options)
end

#chown_mod(owner, group, mode, options = {}) ⇒ Object

Calls Cfruby::FileOps.chown_mod on the file named in the String



66
67
68
# File 'lib/libcfruby/cfrubyscript.rb', line 66

def chown_mod(owner, group, mode, options = {})
	Cfruby::FileOps.chown_mod(self, owner, group, mode, options)
end

#execObject

Calls Cfruby::Exec.exec on the String, allowing for:

'/usr/local/bin/myprogram'.exec()


44
45
46
# File 'lib/libcfruby/cfrubyscript.rb', line 44

def exec()
	return(Cfruby::Exec.exec(self))
end

#exist?Boolean Also known as: exists?

returns true if the file named in the String exists

Returns:

  • (Boolean)


90
91
92
# File 'lib/libcfruby/cfrubyscript.rb', line 90

def exist?()
	return(FileTest.exist?(self))
end

#fileempty?Boolean

returns true if the file named in the String is empty (as defined in Cfruby::FileFind.find() when passed the option :empty => true)

Returns:

  • (Boolean)


98
99
100
101
102
103
104
# File 'lib/libcfruby/cfrubyscript.rb', line 98

def fileempty?()
	Cfruby::FileFind.find(self, :empty => true) { |filename|
		return(true)
	}
	
	return(false)
end

#installObject

Calls Cfruby::Packages::PackageManager.install() on the String, allowing for:

'apache'.install()


35
36
37
38
39
# File 'lib/libcfruby/cfrubyscript.rb', line 35

def install()
	os = Cfruby::OS::OSFactory.new.get_os()
	pkg_manager = os.get_package_manager()
	pkg_manager.install(self)
end

#mkdir(options = {}) ⇒ Object

Calls Cfruby::FileOps.mkdir on the file named in the String



84
85
86
# File 'lib/libcfruby/cfrubyscript.rb', line 84

def mkdir(options = {})
	Cfruby::FileOps.mkdir(self, options)
end

#must_contain(str, options = {}) ⇒ Object

Calls Cfruby::FileEdit.file_must_contain on the file named in the String



54
55
56
# File 'lib/libcfruby/cfrubyscript.rb', line 54

def must_contain(str, options={})
	Cfruby::FileEdit.file_must_contain(self, str, options)
end

#must_not_contain(str, options = {}) ⇒ Object

Calls Cfruby::FileEdit.file_must_not_contain on the file named in the String



60
61
62
# File 'lib/libcfruby/cfrubyscript.rb', line 60

def must_not_contain(str, options={})
	Cfruby::FileEdit.file_must_not_contain(self, str, options)
end

#set(variable, value, options = {}) ⇒ Object

Calls Cfruby::FileEdit.set on the file named in the String



49
50
51
# File 'lib/libcfruby/cfrubyscript.rb', line 49

def set(variable, value, options={})
	Cfruby::FileEdit.set(self, variable, value, options)
end