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-5.3.5-x86-mingw32 lib/hiera/scope.rb
puppet-5.3.5-x64-mingw32 lib/hiera/scope.rb
puppet-5.3.5-universal-darwin lib/hiera/scope.rb
bolt-0.16.1 vendored/puppet/lib/hiera/scope.rb
puppet-5.3.4 lib/hiera/scope.rb
puppet-5.3.4-x86-mingw32 lib/hiera/scope.rb
puppet-5.3.4-x64-mingw32 lib/hiera/scope.rb
puppet-5.3.4-universal-darwin lib/hiera/scope.rb
puppet-4.10.10 lib/hiera/scope.rb
puppet-4.10.10-x86-mingw32 lib/hiera/scope.rb
puppet-4.10.10-x64-mingw32 lib/hiera/scope.rb
puppet-4.10.10-universal-darwin lib/hiera/scope.rb
bolt-0.16.0 vendored/puppet/lib/hiera/scope.rb
bolt-0.15.0 vendored/puppet/lib/hiera/scope.rb
bolt-0.14.0 vendored/puppet/lib/hiera/scope.rb
bolt-0.13.0 vendored/puppet/lib/hiera/scope.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/hiera/scope.rb
bolt-0.12.0 vendored/puppet/lib/hiera/scope.rb
bolt-0.11.0 vendored/puppet/lib/hiera/scope.rb
bolt-0.10.0 vendored/puppet/lib/hiera/scope.rb