Skip to content

Commit ac3e51b

Browse files
author
Travis Fields
committed
Merge branch 'master' into 4.5.x
2 parents 80f0962 + 8db1f2e commit ac3e51b

23 files changed

+551
-194
lines changed

.fixtures.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixtures:
2+
symlinks:
3+
stdlib: "#{source_dir}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ spec/fixtures/
55
.vagrant/
66
.bundle/
77
coverage/
8+
.idea/
9+
*.iml

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
sudo: false
23
language: ruby
34
bundler_args: --without system_tests
45
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"

README.markdown

Lines changed: 84 additions & 58 deletions
Large diffs are not rendered by default.

lib/facter/facter_dot_d.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
class Facter::Util::DotD
1616
require 'yaml'
1717

18-
def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml")
18+
def initialize(dir="/etc/facts.d", cache_file=File.join(Puppet[:libdir], "facts_dot_d.cache"))
1919
@dir = dir
2020
@cache_file = cache_file
2121
@cache = nil
2222
@types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
2323
end
2424

2525
def entries
26-
Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) }
26+
Dir.entries(@dir).reject { |f| f =~ /^\.|\.ttl$/ }.sort.map { |f| File.join(@dir, f) }
2727
rescue
2828
[]
2929
end
@@ -113,7 +113,7 @@ def script_parser(file)
113113

114114
def cache_save!
115115
cache = load_cache
116-
File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
116+
File.open(@cache_file, "w", 0600) { |f| f.write(YAML.dump(cache)) }
117117
rescue
118118
end
119119

lib/puppet/functions/type_of.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Returns the type when passed a value.
2+
#
3+
# @example how to compare values' types
4+
# # compare the types of two values
5+
# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
6+
# @example how to compare against an abstract type
7+
# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
8+
# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
9+
#
10+
# See the documentation for "The Puppet Type System" for more information about types.
11+
# See the `assert_type()` function for flexible ways to assert the type of a value.
12+
#
13+
Puppet::Functions.create_function(:type_of) do
14+
def type_of(value)
15+
Puppet::Pops::Types::TypeCalculator.infer_set(value)
16+
end
17+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Puppet::Parser::Functions
2+
newfunction(:basename, :type => :rvalue, :doc => <<-EOS
3+
Strips directory (and optional suffix) from a filename
4+
EOS
5+
) do |arguments|
6+
7+
if arguments.size < 1 then
8+
raise(Puppet::ParseError, "basename(): No arguments given")
9+
elsif arguments.size > 2 then
10+
raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})")
11+
else
12+
13+
unless arguments[0].is_a?(String)
14+
raise(Puppet::ParseError, 'basename(): Requires string as first argument')
15+
end
16+
17+
if arguments.size == 1 then
18+
rv = File.basename(arguments[0])
19+
elsif arguments.size == 2 then
20+
21+
unless arguments[1].is_a?(String)
22+
raise(Puppet::ParseError, 'basename(): Requires string as second argument')
23+
end
24+
25+
rv = File.basename(arguments[0], arguments[1])
26+
end
27+
28+
end
29+
30+
return rv
31+
end
32+
end
33+
34+
# vim: set ts=2 sw=2 et :

lib/puppet/parser/functions/concat.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
7-
Appends the contents of array 2 onto array 1.
7+
Appends the contents of multiple arrays into array 1.
88
99
*Example:*
1010
11-
concat(['1','2','3'],['4','5','6'])
11+
concat(['1','2','3'],['4','5','6'],['7','8','9'])
1212
1313
Would result in:
1414
15-
['1','2','3','4','5','6']
15+
['1','2','3','4','5','6','7','8','9']
1616
EOS
1717
) do |arguments|
1818

19-
# Check that 2 arguments have been given ...
19+
# Check that more than 2 arguments have been given ...
2020
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
21-
"given (#{arguments.size} for 2)") if arguments.size != 2
21+
"given (#{arguments.size} for < 2)") if arguments.size < 2
2222

2323
a = arguments[0]
24-
b = arguments[1]
2524

2625
# Check that the first parameter is an array
2726
unless a.is_a?(Array)
2827
raise(Puppet::ParseError, 'concat(): Requires array to work with')
2928
end
3029

31-
result = a + Array(b)
30+
result = a
31+
arguments.shift
32+
33+
arguments.each do |x|
34+
result = result + Array(x)
35+
end
3236

3337
return result
3438
end

lib/puppet/parser/functions/delete.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,30 @@ module Puppet::Parser::Functions
1717
delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
1818
Would return: {'a'=>1,'c'=>3}
1919
20+
delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c'])
21+
Would return: {'a'=>1}
22+
2023
delete('abracadabra', 'bra')
2124
Would return: 'acada'
22-
EOS
25+
EOS
2326
) do |arguments|
2427

2528
if (arguments.size != 2) then
2629
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
27-
"given #{arguments.size} for 2.")
30+
"given #{arguments.size} for 2.")
2831
end
2932

3033
collection = arguments[0].dup
31-
item = arguments[1]
32-
33-
case collection
34-
when Array, Hash
35-
collection.delete item
36-
when String
37-
collection.gsub! item, ''
38-
else
39-
raise(TypeError, "delete(): First argument must be an Array, " +
40-
"String, or Hash. Given an argument of class #{collection.class}.")
34+
Array(arguments[1]).each do |item|
35+
case collection
36+
when Array, Hash
37+
collection.delete item
38+
when String
39+
collection.gsub! item, ''
40+
else
41+
raise(TypeError, "delete(): First argument must be an Array, " +
42+
"String, or Hash. Given an argument of class #{collection.class}.")
43+
end
4144
end
4245
collection
4346
end

lib/puppet/parser/functions/ensure_resource.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
items.each do |item|
3737
Puppet::Parser::Functions.function(:defined_with_params)
3838
if function_defined_with_params(["#{type}[#{item}]", params])
39-
Puppet.debug("Resource #{type}[#{item}] not created because it already exists")
39+
Puppet.debug("Resource #{type}[#{item}] with params #{params} not created because it already exists")
4040
else
41+
Puppet.debug("Create new resource #{type}[#{item}] with params #{params}")
4142
Puppet::Parser::Functions.function(:create_resources)
4243
function_create_resources([type.capitalize, { item => params }])
4344
end

0 commit comments

Comments
 (0)