Class Augeas
In: ext/augeas/_augeas.c
lib/augeas.rb
Parent: Object

Wrapper class for the augeas library.

Methods

clear   clear_transforms   defnode   defvar   exists   get   insert   load   load!   match   mv   open   rm   save   save!   set   set!   transform  

Classes and Modules

Class Augeas::Error

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.

[Source]

# 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

[Source]

# File lib/augeas.rb, line 62
    def clear(path)
        set(path, nil)
    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 69
    def clear_transforms
        rm("/augeas/load/*")
    end

Define a variable NAME whose value is the result of evaluating EXPR, which must be non-NULL and evaluate to a nodeset. If a variable NAME already exists, its name will be replaced with the result of evaluating EXPR.

If EXPR evaluates to an empty nodeset, a node is created, equivalent to calling AUG_SET(AUG, EXPR, VALUE) and NAME will be the nodeset containing that single node.

Returns false if aug_defnode fails, and the number of nodes in the nodeset on success.

[Source]

/*
 * call-seq:
 *   defnode(NAME, EXPR, VALUE) -> boolean
 *
 * Define a variable NAME whose value is the result of evaluating EXPR,
 * which must be non-NULL and evaluate to a nodeset. If a variable NAME
 * already exists, its name will be replaced with the result of evaluating
 * EXPR.
 *
 * If EXPR evaluates to an empty nodeset, a node is created, equivalent to
 * calling AUG_SET(AUG, EXPR, VALUE) and NAME will be the nodeset containing
 * that single node.
 *
 * Returns +false+ if +aug_defnode+ fails, and the number of nodes in the
 * nodeset on success.
 */
VALUE augeas_defnode(VALUE s, VALUE name, VALUE expr, VALUE value) {

Define a variable NAME whose value is the result of evaluating EXPR. If a variable NAME already exists, its name will be replaced with the result of evaluating EXPR.

If EXPR is NULL, the variable NAME will be removed if it is defined.

[Source]

/*
 * call-seq:
 *   defvar(NAME, EXPR) -> boolean
 *
 * Define a variable NAME whose value is the result of evaluating EXPR. If
 * a variable NAME already exists, its name will be replaced with the
 * result of evaluating EXPR.
 *
 * If EXPR is NULL, the variable NAME will be removed if it is defined.
 *
 */
VALUE augeas_defvar(VALUE s, VALUE name, VALUE expr) {

Return true if there is an entry for this path, false otherwise

[Source]

/*
 * call-seq:
 *   exists(PATH) -> boolean
 *
 * Return true if there is an entry for this path, false otherwise
 */
VALUE augeas_exists(VALUE s, VALUE path) {

Lookup the value associated with PATH

[Source]

/*
 * call-seq:
 *   get(PATH) -> String
 *
 * Lookup the value associated with PATH
 */
VALUE augeas_get(VALUE s, VALUE path) {

Make LABEL a sibling of PATH by inserting it directly before or after PATH. The boolean BEFORE determines if LABEL is inserted before or after PATH.

[Source]

/*
 * call-seq:
 *   insert(PATH, LABEL, BEFORE) -> int
 *
 * Make LABEL a sibling of PATH by inserting it directly before or after PATH.
 * The boolean BEFORE determines if LABEL is inserted before or after PATH.
 */
VALUE augeas_insert(VALUE s, VALUE path, VALUE label, VALUE before) {

Load files from disk according to the transforms under +/augeas/load+

[Source]

/*
 * call-seq:
 *       load() -> boolean
 *
 * Load files from disk according to the transforms under +/augeas/load+
 */
VALUE augeas_load(VALUE s) {

The same as load, but raises Augeas::Error if loading fails

[Source]

# File lib/augeas.rb, line 103
    def load!
        raise Augeas::Error unless load
    end

Return all the paths that match the path expression PATH as an aray of strings.

[Source]

/*
 * call-seq:
 *       match(PATH) -> an_array
 *
 * Return all the paths that match the path expression PATH as an aray of
 * strings.
 */
VALUE augeas_match(VALUE s, VALUE p) {

Move the node SRC to DST. SRC must match exactly one node in the tree. DST must either match exactly one node in the tree, or may not exist yet. If DST exists already, it and all its descendants are deleted. If DST does not exist yet, it and all its missing ancestors are created.

[Source]

/*
 * call-seq:
 *   mv(SRC, DST) -> int
 *
 * Move the node SRC to DST. SRC must match exactly one node in the
 * tree. DST must either match exactly one node in the tree, or may not
 * exist yet. If DST exists already, it and all its descendants are
 * deleted. If DST does not exist yet, it and all its missing ancestors are
 * created.
 */
VALUE augeas_mv(VALUE s, VALUE src, VALUE dst) {

Remove path and all its children. Returns the number of entries removed

[Source]

/*
 * call-seq:
 *   rm(PATH) -> int
 *
 * Remove path and all its children. Returns the number of entries removed
 */
VALUE augeas_rm(VALUE s, VALUE path, VALUE sibling) {

Write all pending changes to disk

[Source]

/*
 * call-seq:
 *       save() -> boolean
 *
 * Write all pending changes to disk
 */
VALUE augeas_save(VALUE s) {

The same as save, but raises Augeas::Error if saving fails

[Source]

# File lib/augeas.rb, line 98
    def save!
        raise Augeas::Error unless save
    end

Set the value associated with PATH to VALUE. VALUE is copied into the internal data structure. Intermediate entries are created if they don‘t exist.

[Source]

/*
 * call-seq:
 *   set(PATH, VALUE) -> boolean
 *
 * Set the value associated with PATH to VALUE. VALUE is copied into the
 * internal data structure. Intermediate entries are created if they don't
 * exist.
 */
VALUE augeas_set(VALUE s, VALUE path, VALUE value) {

The same as set, but raises Augeas::Error if loading fails

[Source]

# File lib/augeas.rb, line 108
    def set!(path, value)
        raise Augeas::Error unless set(path, value)
    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

[Source]

# File lib/augeas.rb, line 80
    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
        incl = [ incl ] unless incl.is_a?(Array)
        excl = [ excl ] unless incl.is_a?(Array)

        xfm = "/augeas/load/#{name}/"
        set(xfm + "lens", lens)
        incl.each { |inc| set(xfm + "incl[last()+1]", inc) }
        excl.each { |exc| set(xfm + "excl[last()+1]", exc) }
    end

[Validate]