Class: Hiera::Backend::Rspec_backend
- Inherits:
-
Object
- Object
- Hiera::Backend::Rspec_backend
- Defined in:
- lib/hiera/backend/rspec_backend.rb
Instance Method Summary collapse
-
#initialize ⇒ Rspec_backend
constructor
A new instance of Rspec_backend.
- #lookup(key, scope, order_override, resolution_type) ⇒ Object
Constructor Details
#initialize ⇒ Rspec_backend
Returns a new instance of Rspec_backend.
4 5 6 |
# File 'lib/hiera/backend/rspec_backend.rb', line 4 def initialize Hiera.debug("Hiera RSpec backend starting") end |
Instance Method Details
#lookup(key, scope, order_override, resolution_type) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hiera/backend/rspec_backend.rb', line 8 def lookup(key, scope, order_override, resolution_type) answer = nil Hiera.debug("Looking up #{key} in RSpec backend") Backend.datasources(scope, order_override) do |source| Hiera.debug("Looking for data source #{source}") data = Config[:rspec] next if ! data next if data.empty? if data.include?(key) raw_answer = data[key] elsif data.include?(key.to_sym) raw_answer = data[key.to_sym] else next end # Extra logging that we found the key. This can be outputted # multiple times if the resolution type is array or hash but that # should be expected as the logging will then tell the user ALL the # places where the key is found. Hiera.debug("Found #{key} in #{source}") # for array resolution we just append to the array whatever # we find, we then goes onto the next file and keep adding to # the array # # for priority searches we break after the first found data item new_answer = Backend.parse_answer(raw_answer, scope) case resolution_type when :array raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String answer ||= [] answer << new_answer when :hash raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash answer ||= {} answer = new_answer.merge answer else answer = new_answer break end end return answer end |