rspec-hiera-puppet 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -106,7 +106,6 @@ demonstrates the use of a shared context.
106
106
 
107
107
  _spec/spec\_helper.rb_
108
108
 
109
- require 'rspec-hiera'
110
109
  require 'rspec-hiera-puppet'
111
110
 
112
111
  fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
@@ -6,7 +6,7 @@ class Hiera
6
6
  end
7
7
 
8
8
  def lookup(key, scope, order_override, resolution_type)
9
- answer = Backend.empty_answer(resolution_type)
9
+ answer = nil
10
10
 
11
11
  Hiera.debug("Looking up #{key} in RSpec backend")
12
12
 
@@ -26,6 +26,12 @@ class Hiera
26
26
  next
27
27
  end
28
28
 
29
+ # Extra logging that we found the key. This can be outputted
30
+ # multiple times if the resolution type is array or hash but that
31
+ # should be expected as the logging will then tell the user ALL the
32
+ # places where the key is found.
33
+ Hiera.debug("Found #{key} in #{source}")
34
+
29
35
  # for array resolution we just append to the array whatever
30
36
  # we find, we then goes onto the next file and keep adding to
31
37
  # the array
@@ -35,9 +41,11 @@ class Hiera
35
41
  case resolution_type
36
42
  when :array
37
43
  raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
44
+ answer ||= []
38
45
  answer << new_answer
39
46
  when :hash
40
47
  raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
48
+ answer ||= {}
41
49
  answer = new_answer.merge answer
42
50
  else
43
51
  answer = new_answer
@@ -18,126 +18,33 @@ class Puppet::Parser::Compiler
18
18
 
19
19
  def register_function_hiera(spec)
20
20
  Puppet::Parser::Functions.newfunction(:hiera, :type => :rvalue) do |*args|
21
- # Functions called from puppet manifests that look like this:
22
- # lookup("foo", "bar")
23
- # internally in puppet are invoked: func(["foo", "bar"])
24
- #
25
- # where as calling from templates should work like this:
26
- # scope.function_lookup("foo", "bar")
27
- #
28
- # Therefore, declare this function with args '*args' to accept any number
29
- # of arguments and deal with puppet's special calling mechanism now:
30
- if args[0].is_a?(Array)
31
- args = args[0]
32
- end
33
-
34
- key = args[0]
35
- default = args[1]
36
- override = args[2]
37
-
38
- require 'hiera'
39
- require 'hiera/scope'
40
-
41
- hiera = Hiera.new(:config => spec.hiera_config.merge(:logger => 'puppet'))
42
-
43
- if self.respond_to?("[]")
44
- hiera_scope = self
45
- else
46
- hiera_scope = Hiera::Scope.new(self)
47
- end
48
-
49
- answer = hiera.lookup(key, default, hiera_scope, override, :priority)
50
-
51
- raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied") if answer.nil?
52
-
53
- return answer
21
+ require 'hiera_puppet'
22
+ key, default, override = HieraPuppet.parse_args(args)
23
+ HieraPuppet.lookup(key, default, self, override, :priority)
54
24
  end
55
25
  end
56
26
 
57
27
  def register_function_hiera_array(spec)
58
28
  Puppet::Parser::Functions.newfunction(:hiera_array, :type => :rvalue) do |*args|
59
- if args[0].is_a?(Array)
60
- args = args[0]
61
- end
62
-
63
- key = args[0]
64
- default = args[1]
65
- override = args[2]
66
-
67
- require 'hiera'
68
- require 'hiera/scope'
69
-
70
- hiera = Hiera.new(:config => spec.hiera_config.merge(:logger => 'puppet'))
71
-
72
- if self.respond_to?("[]")
73
- hiera_scope = self
74
- else
75
- hiera_scope = Hiera::Scope.new(self)
76
- end
77
-
78
- answer = hiera.lookup(key, default, hiera_scope, override, :array)
79
-
80
- raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied") if answer.empty?
81
-
82
- answer
29
+ require 'hiera_puppet'
30
+ key, default, override = HieraPuppet.parse_args(args)
31
+ HieraPuppet.lookup(key, default, self, override, :array)
83
32
  end
84
33
  end
85
34
 
86
35
  def register_function_hiera_hash(spec)
87
36
  Puppet::Parser::Functions.newfunction(:hiera_hash, :type => :rvalue) do |*args|
88
- if args[0].is_a?(Array)
89
- args = args[0]
90
- end
91
-
92
- raise(Puppet::ParseError, "Please supply a parameter to perform a Hiera lookup") if args.empty?
93
-
94
- key = args[0]
95
- default = args[1]
96
- override = args[2]
97
-
98
- require 'hiera'
99
- require 'hiera/scope'
100
-
101
- hiera = Hiera.new(:config => spec.hiera_config.merge(:logger => 'puppet'))
102
-
103
- if self.respond_to?("{}")
104
- hiera_scope = self
105
- else
106
- hiera_scope = Hiera::Scope.new(self)
107
- end
108
-
109
- answer = hiera.lookup(key, default, hiera_scope, override, :hash)
110
-
111
- raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied") if answer.empty?
112
-
113
- answer
37
+ require 'hiera_puppet'
38
+ key, default, override = HieraPuppet.parse_args(args)
39
+ HieraPuppet.lookup(key, default, self, override, :hash)
114
40
  end
115
41
  end
116
42
 
117
43
  def register_function_hiera_include(spec)
118
44
  Puppet::Parser::Functions.newfunction(:hiera_include) do |*args|
119
- if args[0].is_a?(Array)
120
- args = args[0]
121
- end
122
-
123
- key = args[0]
124
- default = args[1]
125
- override = args[2]
126
-
127
- require 'hiera'
128
- require 'hiera/scope'
129
-
130
- hiera = Hiera.new(:config => spec.hiera_config.merge(:logger => 'puppet'))
131
-
132
- if self.respond_to?("[]")
133
- hiera_scope = self
134
- else
135
- hiera_scope = Hiera::Scope.new(self)
136
- end
137
-
138
- answer = hiera.lookup(key, default, hiera_scope, override, :array)
139
-
140
- raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied") if answer.empty?
45
+ require 'hiera_puppet'
46
+ key, default, override = HieraPuppet.parse_args(args)
47
+ answer = HieraPuppet.lookup(key, default, self, override, :array)
141
48
 
142
49
  method = Puppet::Parser::Functions.function(:include)
143
50
  send(method, answer)
@@ -1,7 +1,7 @@
1
1
  module Rspec
2
2
  module Hiera
3
3
  module Puppet
4
- VERSION = "0.3.0"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -15,9 +15,9 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Rspec::Hiera::Puppet::VERSION
17
17
 
18
- gem.add_dependency('puppet', '>= 2.7')
19
- gem.add_dependency('hiera', '>= 0.3')
20
- gem.add_dependency('hiera-puppet', '>= 0.3')
18
+ gem.add_dependency('puppet', '>= 3.0')
19
+ gem.add_dependency('hiera', '>= 1.0')
20
+ gem.add_dependency('hiera-puppet', '>= 1.0')
21
21
  gem.add_dependency('rspec')
22
22
  gem.add_dependency('rspec-puppet')
23
23
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-hiera-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 3
9
9
  - 0
10
- version: 0.3.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Franz Aigner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-05 00:00:00 Z
18
+ date: 2012-10-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: puppet
@@ -25,11 +25,11 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 13
28
+ hash: 7
29
29
  segments:
30
- - 2
31
- - 7
32
- version: "2.7"
30
+ - 3
31
+ - 0
32
+ version: "3.0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -40,11 +40,11 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- hash: 13
43
+ hash: 15
44
44
  segments:
45
+ - 1
45
46
  - 0
46
- - 3
47
- version: "0.3"
47
+ version: "1.0"
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
@@ -55,11 +55,11 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- hash: 13
58
+ hash: 15
59
59
  segments:
60
+ - 1
60
61
  - 0
61
- - 3
62
- version: "0.3"
62
+ version: "1.0"
63
63
  type: :runtime
64
64
  version_requirements: *id003
65
65
  - !ruby/object:Gem::Dependency