Class: Augeas

Inherits:
Object
  • Object
show all
Defined in:
lib/augeas.rb,
ext/augeas/_augeas.c

Overview

Wrapper class for the augeas library.

Defined Under Namespace

Classes: CommandExecutionError, DescendantError, Error, InternalError, InvalidArgumentError, InvalidLabelError, InvalidPathError, LensNotFoundError, LensSyntaxError, MultipleMatchesError, MultipleTransformsError, NoMatchError, NoMemoryError, NoSpanInfoError

Constant Summary collapse

ERRORS_HASH =
Hash[{
	# the cryptic error names come from the C library, we just make
	# them more ruby and more human
	:ENOMEM    => NoMemoryError,
	:EINTERNAL => InternalError,
	:EPATHX    => InvalidPathError,
	:ENOMATCH  => NoMatchError,
	:EMMATCH   => MultipleMatchesError,
	:ESYNTAX   => LensSyntaxError,
	:ENOLENS   => LensNotFoundError,
	:EMXFM     => MultipleTransformsError,
	:ENOSPAN   => NoSpanInfoError,
	:EMVDESC   => DescendantError,
	:ECMDRUN   => CommandExecutionError,
	:EBADARG   => InvalidArgumentError,
	:ELABEL    => InvalidLabelError,
}.map { |k, v| [(const_get(k) rescue nil), v] }].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(opts = {}, &block) ⇒ Object

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.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/augeas.rb', line 100

def self.create(opts={}, &block)
	# aug_flags is a bitmask in the underlying library, we add all the
	# values of the flags which were set to true to the default value
	# Augeas::NONE (which is 0)
	aug_flags = defined?(Augeas::NO_ERR_CLOSE) ? Augeas::NO_ERR_CLOSE : Augeas::NONE

	flags = {
		:type_check => Augeas::TYPE_CHECK,
		:no_stdinc => Augeas::NO_STDINC,
		:no_load => Augeas::NO_LOAD,
		:no_modl_autoload => Augeas::NO_MODL_AUTOLOAD,
		:enable_span => Augeas::ENABLE_SPAN
	}
	save_modes = {
		:backup => Augeas::SAVE_BACKUP,
		:newfile => Augeas::SAVE_NEWFILE,
		:noop => Augeas::SAVE_NOOP
	}
	opts.each_key do |key|
		if flags.key? key
			aug_flags |= flags[key]
		elsif key == :save_mode
			if save_modes[opts[:save_mode]]
				aug_flags |= save_modes[opts[:save_mode]]
			else
				raise ArgumentError, "Invalid save mode #{opts[:save_mode]}."
			end
		elsif key != :root && key != :loadpath
			raise ArgumentError, "Unknown argument #{key}."
		end
	end

	aug = Augeas::open3(opts[:root], opts[:loadpath], aug_flags)

	begin
		aug.send(:raise_last_error)
	rescue
		aug.close
		raise
	end

	if block_given?
		begin
			yield aug
		ensure
			aug.close
		end
	else
		return aug
	end
end

.open3(r, l, f) ⇒ Object

Define the methods



268
269
270
271
272
273
274
275
276
277
278
279
# File 'ext/augeas/_augeas.c', line 268

VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) {
    unsigned int flags = NUM2UINT(f);
    const char *root = StringValueCStrOrNull(r);
    const char *loadpath = StringValueCStrOrNull(l);
    augeas *aug = NULL;

    aug = aug_init(root, loadpath, flags);
    if (aug == NULL) {
        rb_raise(rb_eSystemCallError, "Failed to initialize Augeas (%d)", errno);
    }
    return Data_Wrap_Struct(c_augeas, NULL, augeas_free, aug);
}

Instance Method Details

#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.

Returns:

  • (Boolean)


255
256
257
258
259
260
261
262
263
264
265
266
# File 'ext/augeas/_augeas.c', line 255

VALUE augeas_defnode(VALUE s, VALUE name, VALUE expr, VALUE value) {
    augeas *aug = aug_handle(s);
    const char *cname = StringValueCStr(name);
    const char *cexpr = StringValueCStrOrNull(expr);
    const char *cvalue = StringValueCStrOrNull(value);

    /* FIXME: Figure out a way to return created, maybe accept a block
       that gets run when created == 1 ? */
    int r = aug_defnode(aug, cname, cexpr, cvalue, NULL);

    return (r < 0) ? Qfalse : INT2NUM(r);
}

#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.

Returns:

  • (Boolean)


229
230
231
232
233
234
235
236
237
# File 'ext/augeas/_augeas.c', line 229

VALUE augeas_defvar(VALUE s, VALUE name, VALUE expr) {
    augeas *aug = aug_handle(s);
    const char *cname = StringValueCStr(name);
    const char *cexpr = StringValueCStrOrNull(expr);

    int r = aug_defvar(aug, cname, cexpr);

    return (r < 0) ? Qfalse : Qtrue;
}

#exists(PATH) ⇒ Boolean

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

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'ext/augeas/_augeas.c', line 73

VALUE augeas_exists(VALUE s, VALUE path) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path);
    int ret = aug_get(aug, cpath, NULL);

    return (ret == 1) ? Qtrue : Qfalse;
}

#get(PATH) ⇒ String

Lookup the value associated with PATH

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'ext/augeas/_augeas.c', line 53

VALUE augeas_get(VALUE s, VALUE path) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path);
    const char *value = NULL;

    int retval = aug_get(aug, cpath, &value);

    if (retval == 1 && value != NULL) {
        return rb_str_new(value, strlen(value));
    } else {
        return Qnil;
    }
}

#insert(PATH, LABEL, BEFORE) ⇒ Integer

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.

Returns:

  • (Integer)


124
125
126
127
128
129
130
131
# File 'ext/augeas/_augeas.c', line 124

VALUE augeas_insert(VALUE s, VALUE path, VALUE label, VALUE before) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path) ;
    const char *clabel = StringValueCStr(label) ;

    int callValue = aug_insert(aug, cpath, clabel, RTEST(before));
    return INT2FIX(callValue) ;
}

#label(PATH) ⇒ String

Lookup the label associated with PATH

Returns:

  • (String)


403
404
405
406
407
408
409
410
411
412
413
414
# File 'ext/augeas/_augeas.c', line 403

VALUE augeas_label(VALUE s, VALUE path) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path);
    const char *label = NULL;

    aug_label(aug, cpath, &label);
    if (label != NULL) {
        return rb_str_new(label, strlen(label)) ;
    } else {
        return Qnil;
    }
}

#loadInteger

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

Returns:

  • (Integer)


212
213
214
215
216
# File 'ext/augeas/_augeas.c', line 212

VALUE augeas_load(VALUE s) {
    augeas *aug = aug_handle(s);
    int callValue = aug_load(aug);
    return INT2FIX(callValue);
}

#match(PATH) ⇒ Array

Return all the paths that match the path expression PATH as an aray of strings. Returns an empty array if no paths were found.

Returns:

  • (Array)


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'ext/augeas/_augeas.c', line 174

VALUE augeas_match(VALUE s, VALUE p) {
    augeas *aug = aug_handle(s);
    const char *path = StringValueCStr(p);
    char **matches = NULL;
    int cnt, i;

    cnt = aug_match(aug, path, &matches) ;
    if (cnt < 0)
        return -1;

    VALUE result = rb_ary_new();
    for (i = 0; i < cnt; i++) {
        rb_ary_push(result, rb_str_new(matches[i], strlen(matches[i])));
        free(matches[i]) ;
    }
    free (matches) ;

    return result ;
}

#mv(SRC, DST) ⇒ Integer

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.

Returns:

  • (Integer)


143
144
145
146
147
148
149
150
# File 'ext/augeas/_augeas.c', line 143

VALUE augeas_mv(VALUE s, VALUE src, VALUE dst) {
    augeas *aug = aug_handle(s);
    const char *csrc = StringValueCStr(src);
    const char *cdst = StringValueCStr(dst);
    int r = aug_mv(aug, csrc, cdst);

    return INT2FIX(r);
}

#rename(SRC, LABEL) ⇒ Integer

Rename the label of all nodes matching SRC to LABEL.

Returns false if aug_rename fails, and the number of nodes renamed on success.

Returns:

  • (Integer)


425
426
427
428
429
430
431
432
# File 'ext/augeas/_augeas.c', line 425

VALUE augeas_rename(VALUE s, VALUE src, VALUE label) {
    augeas *aug = aug_handle(s);
    const char *csrc = StringValueCStr(src);
    const char *clabel = StringValueCStr(label);
    int r = aug_rename(aug, csrc, clabel);

    return (r < 0) ? Qfalse : INT2NUM(r);
}

#rm(PATH) ⇒ Integer

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

Returns:

  • (Integer)


158
159
160
161
162
163
164
# File 'ext/augeas/_augeas.c', line 158

VALUE augeas_rm(VALUE s, VALUE path, VALUE sibling) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path) ;

    int callValue = aug_rm(aug, cpath) ;
    return INT2FIX(callValue) ;
}

#saveInteger

Write all pending changes to disk

Returns:

  • (Integer)


200
201
202
203
204
# File 'ext/augeas/_augeas.c', line 200

VALUE augeas_save(VALUE s) {
    augeas *aug = aug_handle(s);
    int callValue = aug_save(aug);
    return INT2FIX(callValue);
}

#set(PATH, VALUE) ⇒ Integer

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.

Returns:

  • (Integer)


89
90
91
92
93
94
95
96
# File 'ext/augeas/_augeas.c', line 89

VALUE augeas_set(VALUE s, VALUE path, VALUE value) {
    augeas *aug = aug_handle(s);
    const char *cpath = StringValueCStr(path) ;
    const char *cvalue = StringValueCStrOrNull(value) ;

    int callValue = aug_set(aug, cpath, cvalue) ;
    return INT2FIX(callValue);
}

#setm(BASE, SUB, VALUE) ⇒ Boolean

Set multiple nodes in one operation. Find or create a node matching

SUB by interpreting SUB as a path expression relative to each node
matching BASE. SUB may be NULL, in which case all the nodes matching
BASE will be modified.

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
# File 'ext/augeas/_augeas.c', line 107

VALUE augeas_setm(VALUE s, VALUE base, VALUE sub, VALUE value) {
    augeas *aug = aug_handle(s);
    const char *cbase = StringValueCStr(base) ;
    const char *csub = StringValueCStrOrNull(sub) ;
    const char *cvalue = StringValueCStrOrNull(value) ;

    int callValue = aug_setm(aug, cbase, csub, cvalue) ;
    return INT2FIX(callValue);
}

#augeas_span(path) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'ext/augeas/_augeas.c', line 339

VALUE augeas_span(VALUE s, VALUE path) {
    augeas *aug = aug_handle(s);
    char *cpath = StringValueCStr(path);
    char *filename = NULL;
    unsigned int label_start, label_end, value_start, value_end,
        span_start, span_end;
    int r;
    VALUE result;

    r = aug_span(aug, cpath,
                 &filename,
                 &label_start, &label_end,
                 &value_start, &value_end,
                 &span_start, &span_end);

    result = rb_hash_new();

    if (r == 0) {
        hash_set(result, "filename", rb_str_new2(filename));
        hash_set_range(result, "label", label_start, label_end);
        hash_set_range(result, "value", value_start, value_end);
        hash_set_range(result, "span", span_start, span_end);
    }

    free(filename);

    return result;
}

#srun(COMMANDS) ⇒ Array, String

Run one or more newline-separated commands, returning their output.

Returns: an array where the first element is the number of executed commands on success, -1 on failure, and -2 if a ‘quit’ command was encountered. The second element is a string of the output from all commands.

Returns ].

Returns:

  • (Array, String)

    ]



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'ext/augeas/_augeas.c', line 379

VALUE augeas_srun(VALUE s, VALUE text) {
    augeas *aug = aug_handle(s);
    const char *ctext = StringValueCStr(text);

    struct memstream ms;
    __aug_init_memstream(&ms);

    int r = aug_srun(aug, ms.stream, ctext);
    __aug_close_memstream(&ms);

    VALUE result = rb_ary_new();
    rb_ary_push(result, INT2NUM(r));
    rb_ary_push(result, rb_str_new2(ms.buf));

    free(ms.buf);
    return result;
}

#text_retrieve(LENS, NODE_IN, PATH, NODE_OUT) ⇒ Boolean

Transform the tree at PATH into a string using lens LENS and store it in the node NODE_OUT, assuming the tree was initially generated using the value of node NODE_IN. PATH, NODE_IN, and NODE_OUT are path expressions.

Returns:

  • (Boolean)


460
461
462
463
464
465
466
467
468
469
# File 'ext/augeas/_augeas.c', line 460

VALUE augeas_text_retrieve(VALUE s, VALUE lens, VALUE node_in, VALUE path, VALUE node_out) {
    augeas *aug = aug_handle(s);
    const char *clens = StringValueCStr(lens);
    const char *cnode_in = StringValueCStr(node_in);
    const char *cpath = StringValueCStr(path);
    const char *cnode_out = StringValueCStr(node_out);
    int r = aug_text_retrieve(aug, clens, cnode_in, cpath, cnode_out);

    return (r < 0) ? Qfalse : Qtrue;
}

#text_store(LENS, NODE, PATH) ⇒ Boolean

Use the value of node NODE as a string and transform it into a tree using the lens LENS and store it in the tree at PATH, which will be overwritten. PATH and NODE are path expressions.

Returns:

  • (Boolean)


442
443
444
445
446
447
448
449
450
# File 'ext/augeas/_augeas.c', line 442

VALUE augeas_text_store(VALUE s, VALUE lens, VALUE node, VALUE path) {
    augeas *aug = aug_handle(s);
    const char *clens = StringValueCStr(lens);
    const char *cnode = StringValueCStr(node);
    const char *cpath = StringValueCStr(path);
    int r = aug_text_store(aug, clens, cnode, cpath);

    return (r < 0) ? Qfalse : Qtrue;
}

#clear(path) ⇒ Object

Clear the path, i.e. make its value nil



217
218
219
# File 'lib/augeas.rb', line 217

def clear(path)
	augeas_set(path, nil)
end

#clear_transformsObject

Clear all transforms under /augeas/load. If load is called right after this, there will be no files under /files



248
249
250
# File 'lib/augeas.rb', line 248

def clear_transforms
	rm("/augeas/load/*")
end

#clearm(path, sub) ⇒ Object



265
266
267
# File 'lib/augeas.rb', line 265

def clearm(path, sub)
	setm(path, sub, nil)
end

#closeObject

The ‘close` and `error` methods as used unchanged in the ruby bindings



281
282
283
284
285
286
287
288
# File 'ext/augeas/_augeas.c', line 281

VALUE augeas_close (VALUE s) {
    augeas *aug = aug_handle(s);

    aug_close(aug);
    DATA_PTR(s) = NULL;

    return Qnil;
}

#contextObject

Get path expression context (from /augeas/context)



361
362
363
# File 'lib/augeas.rb', line 361

def context
	get('/augeas/context')
end

#context=(path) ⇒ Object

Set path expression context to path (in /augeas/context)



356
357
358
# File 'lib/augeas.rb', line 356

def context=(path)
	set('/augeas/context', path)
end

#defnode(name, expr, value = nil) ⇒ Object

Define the variable name to the result of evaluating expr, which must be a nodeset. If no node matching expr exists yet, one is created and name will refer to it. When a node is created and value is given, the new node’s value is set to value.



212
213
214
# File 'lib/augeas.rb', line 212

def defnode(name, expr, value=nil)
	run_command :augeas_defnode, name, expr, value
end

#defvar(name, expr) ⇒ Object

Evaluate expr and set the variable name to the resulting nodeset. The variable can be used in path expressions as $name. Note that expr is evaluated when the variable is defined, not when it is used.



204
205
206
# File 'lib/augeas.rb', line 204

def defvar(name, expr)
	run_command :augeas_defvar, name, expr
end

#errorObject

Retrieve details about the last error encountered and return those details in a HASH with the following entries:

  • :code error code from aug_error

  • :message error message from aug_error_message

  • :minor minor error message from aug_minor_error_message

  • :details error details from aug_error_details



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'ext/augeas/_augeas.c', line 305

VALUE augeas_error(VALUE s) {
    augeas *aug = aug_handle(s);
    int code;
    const char *msg = NULL;
    VALUE result;

    result = rb_hash_new();

    code = aug_error(aug);
    hash_set(result, "code", INT2NUM(code));

    msg = aug_error_message(aug);
    if (msg != NULL)
        hash_set(result, "message", rb_str_new2(msg));

    msg = aug_error_minor_message(aug);
    if (msg != NULL)
        hash_set(result, "minor", rb_str_new2(msg));

    msg = aug_error_details(aug);
    if (msg != NULL)
        hash_set(result, "details", rb_str_new2(msg));

    return result;
}

#exists(path) ⇒ Object

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



158
159
160
# File 'lib/augeas.rb', line 158

def exists(path)
	run_command :augeas_exists, path
end

#get(path) ⇒ Object

Get the value associated with path.



153
154
155
# File 'lib/augeas.rb', line 153

def get(path)
	run_command :augeas_get, path
end

#insert(path, label, before) ⇒ Object

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.



351
352
353
# File 'lib/augeas.rb', line 351

def insert(path, label, before)
	run_command :augeas_insert, path, label, before
end

#label(path) ⇒ Object

Lookup the label associated with path Raises Augeas::NoMatchError if the path node does not exist



322
323
324
# File 'lib/augeas.rb', line 322

def label(path)
	run_command :augeas_label, path
end

#loadObject

Load files according to the transforms in /augeas/load or those defined via transform. A transform Foo is represented with a subtree /augeas/load/Foo. Underneath /augeas/load/Foo, one node labeled ‘lens’ must exist, whose value is the fully qualified name of a lens, for example ‘Foo.lns’, and multiple nodes ‘incl’ and ‘excl’ whose values are globs that determine which files are transformed by that lens. It is an error if one file can be processed by multiple transforms.



277
278
279
280
281
282
283
284
285
286
# File 'lib/augeas.rb', line 277

def load
	begin
		run_command :augeas_load
	rescue Augeas::CommandExecutionError => e
		raise e, "Loading failed. Search the augeas tree in /augeas//error"+
			"for the actual errors."
	end

	nil
end

#match(path) ⇒ Object

Return an Array of all the paths that match the path expression path

Returns an empty Array if no paths were found. Raises an Augeas::InvalidPathError when the path is invalid.



191
192
193
# File 'lib/augeas.rb', line 191

def match(path)
	run_command :augeas_match, path
end

#mv(src, dst) ⇒ Object

Move 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.

Raises Augeas::NoMatchError if the src node does not exist Raises Augeas::MultipleMatchesError if there were multiple matches in src Raises Augeas::DescendantError if the dst node is a descendant of the src node.



299
300
301
# File 'lib/augeas.rb', line 299

def mv(src, dst)
	run_command :augeas_mv, src, dst
end

#rename(path, label) ⇒ Object

Rename the label of all nodes matching path to label Raises Augeas::NoMatchError if the path node does not exist Raises Augeas::InvalidLabelError if label is invalid



329
330
331
# File 'lib/augeas.rb', line 329

def rename(path, label)
	run_command :augeas_rename, path, label
end

#rm(path) ⇒ Object

Remove all nodes matching path expression path and all their children. Raises an Augeas::InvalidPathError when the path is invalid.



183
184
185
# File 'lib/augeas.rb', line 183

def rm(path)
	run_command :augeas_rm, path
end

#saveObject

Write all pending changes to disk. Raises Augeas::CommandExecutionError if saving fails.



254
255
256
257
258
259
260
261
262
263
# File 'lib/augeas.rb', line 254

def save
	begin
		run_command :augeas_save
	rescue Augeas::CommandExecutionError => e
		raise e, 'Saving failed. Search the augeas tree in /augeas//error ' <<
			'for the actual errors.'
	end

	nil
end

#set(path, *values) ⇒ Object

Set one or multiple elements to path. Multiple elements are mainly sensible with a path like …/array, since this will append all elements.



165
166
167
# File 'lib/augeas.rb', line 165

def set(path, *values)
	values.flatten.each { |v| run_command :augeas_set, path, v }
end

#setm(base, sub, value) ⇒ Object

base the base node sub the subtree relative to the base value the value for the nodes



176
177
178
# File 'lib/augeas.rb', line 176

def setm(base, sub, value)
	run_command :augeas_setm, base, sub, value
end

#span(path) ⇒ Object

Get the filename, label and value position in the text of this node

Raises Augeas::NoMatchError if the node could not be found Raises Augeas::NoSpanInfo if the node associated with path doesn’t belong to a file or doesn’t exist



308
309
310
# File 'lib/augeas.rb', line 308

def span(path)
	run_command :augeas_span, path
end

#srun(text) ⇒ Object

Run one or more newline-separated commands specified by text, returns an array of [successful_commands_number, output] or

-2, output

in case ‘quit’ command has been encountered.

Raises Augeas::CommandExecutionError if gets an invalid command



316
317
318
# File 'lib/augeas.rb', line 316

def srun(text)
	run_command(:augeas_srun, text)
end

#text_retrieve(lens, node_in, path, node_out) ⇒ Object

Transform the tree at path into a string lens lens and store it in the node node_out, assuming the tree was initially generated using the value of node node_in. path, node_in and node_out are path expressions.



343
344
345
# File 'lib/augeas.rb', line 343

def text_retrieve(lens, node_in, path, node_out)
	run_command :augeas_text_retrieve, lens, node_in, path, node_out
end

#text_store(lens, node, path) ⇒ Object

Use the value of node node as a string and transform it into a tree using the lens lens and store it in the tree at path, which will be overwritten. path and node are path expressions.



336
337
338
# File 'lib/augeas.rb', line 336

def text_store(lens, node, path)
	run_command :augeas_text_store, lens, node, path
end

#touch(path) ⇒ Object

Create the path with empty value if it doesn’t exist



196
197
198
# File 'lib/augeas.rb', line 196

def touch(path)
	set(path, nil) if match(path).empty?
end

#transform(hash) ⇒ Object

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

Raises:

  • (ArgumentError)


230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/augeas.rb', line 230

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