/usr/lib/ruby/vendor_ruby/augeas.rb is in ruby-augeas 1:0.5.0-3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 | ##
# augeas.rb: Ruby wrapper for augeas
#
# Copyright (C) 2008 Red Hat Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Bryan Kearney <bkearney@redhat.com>
##
require "_augeas"
# Wrapper class for the augeas[http://augeas.net] library.
class Augeas
private_class_method :new
class Error < RuntimeError; 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 <tt>enum aug_flags</tt>)
#
# 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.
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
# Set one or multiple elemens to path.
# Multiple elements are mainly sensible with a path like
# .../array[last()+1], since this will append all elements.
def set(path, *values)
values.flatten.each { |v| set_internal(path, v) }
end
# The same as +set+, but raises <tt>Augeas::Error</tt> if setting fails
def set!(path, *values)
values.flatten.each do |v|
raise Augeas::Error unless set_internal(path, v)
end
end
# Clear the +path+, i.e. make its value +nil+
def clear(path)
set_internal(path, 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.
def clearm(base, sub)
setm(base, sub, nil)
end
# Create the +path+ with empty value if it doesn't exist
def touch(path)
set_internal(path, nil) if match(path).empty?
end
# Clear all transforms under <tt>/augeas/load</tt>. If +load+
# is called right after this, there will be no files
# under +/files+
def clear_transforms
rm("/augeas/load/*")
end
# Add a transform under <tt>/augeas/load</tt>
#
# The HASH can contain the following entries
# * <tt>:lens</tt> - the name of the lens to use
# * <tt>:name</tt> - a unique name; use the module name of the LENS when omitted
# * <tt>:incl</tt> - a list of glob patterns for the files to transform
# * <tt>:excl</tt> - a list of the glob patterns to remove from the list that matches <tt>:INCL</tt>
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
# The same as +save+, but raises <tt>Augeas::Error</tt> if saving fails
def save!
raise Augeas::Error unless save
end
# The same as +load+, but raises <tt>Augeas::Error</tt> if loading fails
def load!
raise Augeas::Error unless load
end
# Set path expression context to +path+ (in /augeas/context)
def context=(path)
set_internal('/augeas/context', path)
end
# Get path expression context (from /augeas/context)
def context
get('/augeas/context')
end
end
|