class Augeas
Wrapper class for the augeas library.
Public Class Methods
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
Public Instance Methods
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 95 def clear_transforms rm("/augeas/load/*") end
Clear multiple nodes values in one operation. Find or create a node
matching sub
by interpreting sub
as a path
expression relative to each node matching base
. If
sub
is '.', the nodes matching base
will
be modified.
# File lib/augeas.rb, line 83 def clearm(base, sub) setm(base, sub, nil) end
Get path expression context (from /augeas/context)
# File lib/augeas.rb, line 138 def context get('/augeas/context') end
Set path expression context to path
(in /augeas/context)
# File lib/augeas.rb, line 133 def context=(path) set_internal('/augeas/context', path) end
The same as load
, but raises Augeas::Error
if
loading fails
# File lib/augeas.rb, line 128 def load! raise Augeas::Error unless load end
The same as save
, but raises Augeas::Error
if
saving fails
# File lib/augeas.rb, line 123 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
Create the path
with empty value if it doesn't exist
# File lib/augeas.rb, line 88 def touch(path) set_internal(path, nil) if match(path).empty? 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 106 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 lens = "#{lens}.lns" unless lens.include? '.' 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