Sha256: 168e702e3bb94006bc251f2322e52de6152dabcfcfe3ff623cfce5f4d474ff27

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

class Hiera
  module Backend
    class Json_backend
      def initialize
        require 'json'

        Hiera.debug("Hiera JSON backend starting")
      end

      def lookup(key, scope, order_override, resolution_type)
        answer = nil

        Hiera.debug("Looking up #{key} in JSON backend")

        Backend.datasources(scope, order_override) do |source|
          Hiera.debug("Looking for data source #{source}")

          jsonfile = Backend.datafile(:json, scope, source, "json") || next

          data = JSON.parse(File.read(jsonfile))

          next if data.empty?
          next unless data.include?(key)

          # 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(data[key], scope)
          case resolution_type
          when :array
            answer ||= []
            answer << new_answer
          else
            answer = Backend.parse_answer(data[key], scope)
            break
          end
        end

        return answer
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/hiera-1.1.2/lib/hiera/backend/json_backend.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/hiera-1.1.2/lib/hiera/backend/json_backend.rb
hiera-1.1.2 lib/hiera/backend/json_backend.rb
hiera-1.1.2.rc2 lib/hiera/backend/json_backend.rb
hiera-1.1.2.rc1 lib/hiera/backend/json_backend.rb
hiera-1.1.1 lib/hiera/backend/json_backend.rb
hiera-1.1.1.rc1 lib/hiera/backend/json_backend.rb
hiera-1.1.0 lib/hiera/backend/json_backend.rb
hiera-1.1.0.rc1 lib/hiera/backend/json_backend.rb