Wrapper class for the augeas library.
Create a new Augeas instance and return it.
Use root as the filesystem root. If root is nil, use the value of the environment variable AUGEAS_ROOT. If that doesn't exist either, use "/".
loadpath is a colon-spearated list of directories that modules should be searched in. This is in addition to the standard load path and the directories in AUGEAS_LENS_LIB
flags is a bitmask (see enum aug_flags)
When a block is given, the Augeas instance is passed as the only argument into the block and closed when the block exits. In that case, the return value of the block is the return value of open. With no block, the Augeas instance is returned.
# File lib/augeas.rb, line 47 def self.open(root = nil, loadpath = nil, flags = NONE, &block) aug = open3(root, loadpath, flags) if block_given? begin rv = yield aug return rv ensure aug.close end else return aug end end
Clear the path, i.e. make its value nil
# File lib/augeas.rb, line 76 def clear(path) set_internal(path, nil) end
Clear all transforms under /augeas/load. If load is called right after this, there will be no files under /files
# File lib/augeas.rb, line 83 def clear_transforms rm("/augeas/load/*") end
The same as load, but raises Augeas::Error if loading fails
# File lib/augeas.rb, line 115 def load! raise Augeas::Error unless load end
The same as save, but raises Augeas::Error if saving fails
# File lib/augeas.rb, line 110 def save! raise Augeas::Error unless save end
Set one or multiple elemens to path. Multiple elements are mainly sensible with a path like .../array, since this will append all elements.
# File lib/augeas.rb, line 64 def set(path, *values) values.flatten.each { |v| set_internal(path, v) } end
The same as set, but raises Augeas::Error if setting fails
# File lib/augeas.rb, line 69 def set!(path, *values) values.flatten.each do |v| raise Augeas::Error unless set_internal(path, v) end end
Add a transform under /augeas/load
The HASH can contain the following entries
:lens - the name of the lens to use
:name - a unique name; use the module name of the LENS when omitted
:incl - a list of glob patterns for the files to transform
:excl - a list of the glob patterns to remove from the list that matches :INCL
# File lib/augeas.rb, line 94 def transform(hash) lens = hash[:lens] name = hash[:name] incl = hash[:incl] excl = hash[:excl] raise ArgumentError, "No lens specified" unless lens raise ArgumentError, "No files to include" unless incl name = lens.split(".")[0].sub("@", "") unless name xfm = "/augeas/load/#{name}/" set(xfm + "lens", lens) set(xfm + "incl[last()+1]", incl) set(xfm + "excl[last()+1]", excl) if excl end
Generated with the Darkfish Rdoc Generator 2.