class Augeas
Wrapper class for the augeas library.
Constants
- ERRORS_HASH
Public Class Methods
Source
# File lib/augeas.rb, line 98 def self.create(opts={}, &block) Augeas::Facade::create(opts, &block) end
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
The following flags can be specified in a hash. They all default to false and can be enabled by setting them to true
:type_check - typecheck lenses (since it can be very expensive it is not done by default)
:no_stdinc - do not use the builtin load path for modules
:no_load - do not load the tree during the initialization phase
:no_modl_autoload - do not load the tree during the initialization phase
:enable_span - track the span in the input nodes
:save_mode can be one of :backup, :newfile, :noop as explained below.
:noop - make save a no-op process, just record what would have changed :backup - keep the original file with an .augsave extension :newfile - save changes into a file with an .augnew extension and do not overwrite the original file.
When a block is given, the Augeas instance is passed as the only argument into the block and closed when the block exits. With no block, the Augeas instance is returned.
Source
# File lib/augeas.rb, line 118 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
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.
Public Instance Methods
Source
# File lib/augeas.rb, line 147 def clear(path) set_internal(path, nil) end
Clear the path, i.e. make its value nil
Source
# File lib/augeas.rb, line 166 def clear_transforms rm("/augeas/load/*") end
Clear all transforms under /augeas/load. If load is called right after this, there will be no files under /files
Source
# File lib/augeas.rb, line 154 def clearm(base, sub) setm(base, sub, nil) 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.
Source
# File lib/augeas.rb, line 209 def context get('/augeas/context') end
Get path expression context (from /augeas/context)
Source
# File lib/augeas.rb, line 204 def context=(path) set_internal('/augeas/context', path) end
Set path expression context to path (in /augeas/context)
Source
# File lib/augeas.rb, line 199 def load! raise Augeas::Error unless load end
The same as load, but raises Augeas::Error if loading fails
Source
# File lib/augeas.rb, line 194 def save! raise Augeas::Error unless save end
The same as save, but raises Augeas::Error if saving fails
Source
# File lib/augeas.rb, line 135 def set(path, *values) values.flatten.each { |v| set_internal(path, v) } end
Set one or multiple elemens to path. Multiple elements are mainly sensible with a path like …/array, since this will append all elements.
Source
# File lib/augeas.rb, line 140 def set!(path, *values) values.flatten.each do |v| raise Augeas::Error unless set_internal(path, v) end end
The same as set, but raises Augeas::Error if setting fails
Source
# File lib/augeas.rb, line 159 def touch(path) set_internal(path, nil) if match(path).empty? end
Create the path with empty value if it doesn’t exist
Source
# File lib/augeas.rb, line 177 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
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