Module: AugeasProviders::Provider
- Defined in:
- lib/augeasproviders/provider.rb
Overview
Mixin to add Augeas-related helpers to Puppet providers.
Handles basics such as opening, accessing and saving changes via an Augeas
handle, plus standard configuration from a Puppet resource (e.g. the target
parameter).
To use, include in the provider:
Puppet::Type.type(:example).provide(:augeas) do
include AugeasProviders::Provider
# [..]
end
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary (collapse)
-
+ (Object) loadpath
private
Override Augeas' loadpath, usually for testing with a separate Augeas checkout.
Instance Method Summary (collapse)
-
- (Augeas) aug_handler
private
Returns an Augeas handler.
-
- (String) aug_version
Returns the Augeas version used.
-
- (Object) augclose!(aug)
Close the shared Augeas handler.
-
- (Augeas) augopen(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... }
Opens Augeas and returns a handle to use.
-
- (Augeas) augopen!(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... }
Opens Augeas and returns a handle to use.
-
- (Object) augsave!(aug, reload = false)
Saves all changes made in the current Augeas handle and checks for any errors while doing so.
-
- (Boolean) parsed_as?(text, path, lens = nil)
Returns whether text is parsed as path using lens.
-
- (String) path_label(aug, path)
Wrapper around Augeas#label for older versions of Augeas.
-
- (String) quoteit(value, oldvalue = nil)
Automatically quote a value.
-
- (Symbol) readquote(value)
Detect what type of quoting a value uses.
-
- (String) resource_path
Gets the Augeas path expression representing the individual resource inside the file, that represents the current Puppet resource.
-
- (Object) setvars(aug)
Sets useful Augeas variables for the session:.
-
- (Boolean) supported?(feature)
Returns whether a feature is supported.
-
- (String) target
Gets the path expression representing the file being managed for the current Puppet resource.
-
- (String) unquoteit(value)
Automatically unquote a value.
Class Attribute Details
+ (Object) loadpath
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Augeas' loadpath, usually for testing with a separate Augeas checkout.
28 29 30 |
# File 'lib/augeasproviders/provider.rb', line 28 def loadpath @loadpath end |
Instance Method Details
- (Augeas) aug_handler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an Augeas handler.
On Puppet >= 3.4, stores and returns a shared Augeas handler for all instances of the class
815 816 817 |
# File 'lib/augeasproviders/provider.rb', line 815 def aug_handler self.class.aug_handler end |
- (String) aug_version
Returns the Augeas version used
724 725 726 |
# File 'lib/augeasproviders/provider.rb', line 724 def aug_version self.class.aug_version end |
- (Object) augclose!(aug)
Close the shared Augeas handler.
804 805 806 |
# File 'lib/augeasproviders/provider.rb', line 804 def augclose!(aug) self.class.augclose!(aug) end |
- (Augeas) augopen(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... }
Opens Augeas and returns a handle to use. It loads only the file for the current Puppet resource using AugeasProviders::Provider::ClassMethods#lens.
If called with a block, this will be yielded to and the Augeas handle
closed after the block has executed (on Puppet < 3.4.0).
Otherwise, the handle will be returned and not closed automatically.
On Puppet >= 3.4, the handle will be closed by post_resource_eval
.
On older versions, the caller is responsible for closing it to free
resources.
If yield_resource
is set to true, the supplied resource
will be passed
as a yieldparam to the block, after the aug
handle. Any arguments passed
after yield_resource
will be added as yieldparams to the block.
763 764 765 |
# File 'lib/augeasproviders/provider.rb', line 763 def augopen(yield_resource = false, *yield_params, &block) self.class.augopen(self.resource, yield_resource, *yield_params, &block) end |
- (Augeas) augopen!(yield_resource = false, *yield_params) {|aug, resource, *yield_params| ... }
Opens Augeas and returns a handle to use. It loads only the file for the current Puppet resource using AugeasProviders::Provider::ClassMethods#lens.
augsave! is called after the block is evaluated.
If called with a block, this will be yielded to and the Augeas handle
closed after the block has executed (on Puppet < 3.4.0).
Otherwise, the handle will be returned and not closed automatically.
On Puppet >= 3.4, the handle will be closed by post_resource_eval
.
On older versions, the caller is responsible for closing it to free
resources.
785 786 787 |
# File 'lib/augeasproviders/provider.rb', line 785 def augopen!(yield_resource = false, *yield_params, &block) self.class.augopen!(self.resource, yield_resource, *yield_params, &block) end |
- (Object) augsave!(aug, reload = false)
Saves all changes made in the current Augeas handle and checks for any errors while doing so.
796 797 798 |
# File 'lib/augeasproviders/provider.rb', line 796 def augsave!(aug, reload = false) self.class.augsave!(aug, reload) end |
- (Boolean) parsed_as?(text, path, lens = nil)
Returns whether text is parsed as path using lens
907 908 909 910 |
# File 'lib/augeasproviders/provider.rb', line 907 def parsed_as?(text, path, lens = nil) lens ||= self.class.lens(self.resource) self.class.parsed_as?(text, path, lens) end |
- (String) path_label(aug, path)
Wrapper around Augeas#label for older versions of Augeas
825 826 827 |
# File 'lib/augeasproviders/provider.rb', line 825 def path_label(aug, path) self.class.path_label(aug, path) end |
- (String) quoteit(value, oldvalue = nil)
Automatically quote a value
835 836 837 |
# File 'lib/augeasproviders/provider.rb', line 835 def quoteit(value, oldvalue = nil) self.class.quoteit(value, self.resource, oldvalue) end |
- (Symbol) readquote(value)
Detect what type of quoting a value uses
844 845 846 |
# File 'lib/augeasproviders/provider.rb', line 844 def readquote(value) self.class.readquote(value) end |
- (String) resource_path
Gets the Augeas path expression representing the individual resource inside the file, that represents the current Puppet resource.
If no block was set by the provider's class method, it returns the path expression representing the top-level of the file.
858 859 860 |
# File 'lib/augeasproviders/provider.rb', line 858 def resource_path self.class.resource_path(self.resource) end |
- (Object) setvars(aug)
Sets useful Augeas variables for the session:
$target
points to the root of the target file$resource
points to path defined by #resource_path
It also sets /augeas/context
to the target file so
relative paths can be used, before the variables are set.
If supplied with a resource, it will be used to determine the path to the used file.
876 877 878 |
# File 'lib/augeasproviders/provider.rb', line 876 def setvars(aug) self.class.setvars(aug, self.resource) end |
- (Boolean) supported?(feature)
Returns whether a feature is supported.
The following features are currently supported:
:regexpi
: whether Augeas supports an 'i' flag in regexp expressions:post_resource_eval
: whether Puppet supportspost_resource_eval
hooks
738 739 740 |
# File 'lib/augeasproviders/provider.rb', line 738 def supported?(feature) self.class.supported?(feature) end |
- (String) target
Gets the path expression representing the file being managed for the current Puppet resource.
887 888 889 |
# File 'lib/augeasproviders/provider.rb', line 887 def target self.class.target(self.resource) end |
- (String) unquoteit(value)
Automatically unquote a value
896 897 898 |
# File 'lib/augeasproviders/provider.rb', line 896 def unquoteit(value) self.class.unquoteit(value) end |