Sha256: 7668d7e906ed3344df420ec889f106e1342b95eab7a2bce289b85ed0fa672613

Contents?: true

Size: 1.31 KB

Versions: 148

Compression:

Stored size: 1.31 KB

Contents

class Hiera
  class Scope
    CALLING_CLASS = 'calling_class'.freeze
    CALLING_CLASS_PATH = 'calling_class_path'.freeze
    CALLING_MODULE = 'calling_module'.freeze
    MODULE_NAME = 'module_name'.freeze

    CALLING_KEYS = [CALLING_CLASS, CALLING_CLASS_PATH, CALLING_MODULE].freeze
    EMPTY_STRING = ''.freeze

    attr_reader :real

    def initialize(real)
      @real = real
    end

    def [](key)
      if key == CALLING_CLASS
        ans = find_hostclass(@real)
      elsif key == CALLING_CLASS_PATH
        ans = find_hostclass(@real).gsub(/::/, '/')
      elsif key == CALLING_MODULE
        ans = @real.lookupvar(MODULE_NAME)
      else
        ans = @real.lookupvar(key)
      end
      ans == EMPTY_STRING ? nil : ans
    end

    def exist?(key)
      CALLING_KEYS.include?(key) || @real.exist?(key)
    end

    def include?(key)
      CALLING_KEYS.include?(key) || @real.include?(key)
    end

    def catalog
      @real.catalog
    end

    def resource
      @real.resource
    end

    def compiler
      @real.compiler
    end

    def find_hostclass(scope)
      if scope.source and scope.source.type == :hostclass
        return scope.source.name.downcase
      elsif scope.parent
        return find_hostclass(scope.parent)
      else
        return nil
      end
    end
    private :find_hostclass
  end
end

Version data entries

148 entries across 148 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/hiera/scope.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/hiera/scope.rb
puppet-5.3.7 lib/hiera/scope.rb
puppet-5.3.7-x86-mingw32 lib/hiera/scope.rb
puppet-5.3.7-x64-mingw32 lib/hiera/scope.rb
puppet-5.3.7-universal-darwin lib/hiera/scope.rb
puppet-4.10.12 lib/hiera/scope.rb
puppet-4.10.12-x86-mingw32 lib/hiera/scope.rb
puppet-4.10.12-x64-mingw32 lib/hiera/scope.rb
puppet-4.10.12-universal-darwin lib/hiera/scope.rb
bolt-0.20.3 vendored/puppet/lib/hiera/scope.rb
bolt-0.20.2 vendored/puppet/lib/hiera/scope.rb
bolt-0.19.1 vendored/puppet/lib/hiera/scope.rb
puppet-4.10.11 lib/hiera/scope.rb
puppet-4.10.11-x86-mingw32 lib/hiera/scope.rb
puppet-4.10.11-x64-mingw32 lib/hiera/scope.rb
puppet-4.10.11-universal-darwin lib/hiera/scope.rb
puppet-5.3.6 lib/hiera/scope.rb
puppet-5.3.6-x86-mingw32 lib/hiera/scope.rb
puppet-5.3.6-x64-mingw32 lib/hiera/scope.rb