Skip to content

Commit

Permalink
Added support for including Puppets pluginsync libdir into the loadpath
Browse files Browse the repository at this point in the history
  • Loading branch information
crayfishx authored and Dominic Cleal committed Oct 5, 2013
1 parent 5be2202 commit 818712d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/augeasproviders/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ def unquoteit(value)

private

# Returns a set of load paths to use when initialising Augeas.
#
# @return [String] colon-separated string of module paths, or nil if defaults are to be used
def loadpath
loadpath = AugeasProviders::Provider.loadpath
plugins = File.join(Puppet[:libdir], 'augeas', 'lenses')
if File.exists?(plugins)
loadpath = loadpath.to_s.split(File::PATH_SEPARATOR).push(plugins).join(File::PATH_SEPARATOR)
end
loadpath
end

# Opens Augeas and returns a handle to use. It loads only the file
# identified by {#target} (and the supplied `resource`) using {#lens}.
#
Expand All @@ -543,7 +555,6 @@ def unquoteit(value)
# @raise [Puppet::Error] if Augeas did not load the file
# @api private
def augopen_internal(resource = nil, autosave = false, yield_resource = false, *yield_params, &block)
loadpath = AugeasProviders::Provider.loadpath
file = target(resource)
aug = nil
begin
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/augeasproviders/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ class Test
end
end

describe "#loadpath" do
it "should return AugeasProviders::Provider.loadpath" do
subject.send(:loadpath).should == AugeasProviders::Provider.loadpath
end

it "should add libdir/augeas/lenses/ to the loadpath if it exists" do
plugindir = File.join(Puppet[:libdir], 'augeas', 'lenses')
File.expects(:exists?).with(plugindir).returns(true)
subject.send(:loadpath).should == "#{AugeasProviders::Provider.loadpath}:#{plugindir}"
end
end

describe "#augopen" do
before do
subject.expects(:augsave!).never
Expand Down

0 comments on commit 818712d

Please sign in to comment.