File tree 3 files changed +49
-0
lines changed
lib/puppet/parser/functions
spec/unit/puppet/parser/functions
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,16 @@ Would return: ['a','c']
195
195
196
196
- * Type* : rvalue
197
197
198
+ dirname
199
+ -------
200
+ Returns the ` dirname ` of a path.
201
+
202
+ * Examples:*
203
+
204
+ dirname('/path/to/a/file.ext')
205
+
206
+ Would return: '/path/to/a'
207
+
198
208
downcase
199
209
--------
200
210
Converts the case of a string or all strings in an array to lower case.
Original file line number Diff line number Diff line change
1
+ module Puppet ::Parser ::Functions
2
+ newfunction ( :dirname , :type => :rvalue , :doc => <<-EOS
3
+ Returns the dirname of a path.
4
+ EOS
5
+ ) do |arguments |
6
+
7
+ raise ( Puppet ::ParseError , "dirname(): Wrong number of arguments " +
8
+ "given (#{ arguments . size } for 1)" ) if arguments . size < 1
9
+
10
+ path = arguments [ 0 ]
11
+ return File . dirname ( path )
12
+ end
13
+ end
14
+
15
+ # vim: set ts=2 sw=2 et :
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env ruby -S rspec
2
+ require 'spec_helper'
3
+
4
+ describe "the dirname function" do
5
+ let ( :scope ) { PuppetlabsSpec ::PuppetInternals . scope }
6
+
7
+ it "should exist" do
8
+ Puppet ::Parser ::Functions . function ( "dirname" ) . should == "function_dirname"
9
+ end
10
+
11
+ it "should raise a ParseError if there is less than 1 arguments" do
12
+ lambda { scope . function_dirname ( [ ] ) } . should ( raise_error ( Puppet ::ParseError ) )
13
+ end
14
+
15
+ it "should return dirname for an absolute path" do
16
+ result = scope . function_dirname ( [ '/path/to/a/file.ext' ] )
17
+ result . should ( eq ( '/path/to/a' ) )
18
+ end
19
+
20
+ it "should return dirname for a relative path" do
21
+ result = scope . function_dirname ( [ 'path/to/a/file.ext' ] )
22
+ result . should ( eq ( 'path/to/a' ) )
23
+ end
24
+ end
You can’t perform that action at this time.
0 commit comments