403Webshell
Server IP : 172.67.158.161  /  Your IP : 3.129.67.38
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup/lookup_key.rb
require_relative 'sub_lookup'

module Puppet::Pops
module Lookup
# @api private
class LookupKey
  include SubLookup

  attr_reader :module_name, :root_key, :segments

  def initialize(key)
    segments = split_key(key) { |problem| Puppet::DataBinding::LookupError.new(_("%{problem} in key: '%{key}'") % { problem: problem, key: key }) }
    root_key = segments.shift.freeze
    qual_index = root_key.index(DOUBLE_COLON)

    @key = key
    @module_name = qual_index.nil? ? nil : root_key[0..qual_index-1].freeze
    @root_key = root_key
    @segments = segments.empty? ? nil : segments.freeze
  end

  def dig(lookup_invocation, value)
    @segments.nil? ? value : sub_lookup(@key, lookup_invocation, @segments, value)
  end

  # Prunes a found root value with respect to subkeys in this key. The given _value_ is returned untouched
  # if this key has no subkeys. Otherwise an attempt is made to create a Hash or Array that contains only the
  # path to the appointed value and that value.
  #
  # If subkeys exists and no value is found, then this method will return `nil`, an empty `Array` or an empty `Hash`
  # to enable further merges to be applied. The returned type depends on the given _value_.
  #
  # @param value [Object] the value to prune
  # @return the possibly pruned value
  def prune(value)
    if @segments.nil?
      value
    else
      pruned = @segments.reduce(value) do |memo, segment|
        memo.is_a?(Hash) || memo.is_a?(Array) && segment.is_a?(Integer) ? memo[segment] : nil
      end
      if pruned.nil?
        case value
        when Hash
          EMPTY_HASH
        when Array
          EMPTY_ARRAY
        else
          nil
        end
      else
        undig(pruned)
      end
    end
  end

  # Create a structure that can be dug into using the subkeys of this key in order to find the
  # given _value_. If this key has no subkeys, the _value_ is returned.
  #
  # @param value [Object] the value to wrap in a structure in case this value has subkeys
  # @return [Object] the possibly wrapped value
  def undig(value)
    @segments.nil? ? value : segments.reverse.reduce(value) do |memo, segment|
      if segment.is_a?(Integer)
        x = []
        x[segment] = memo
      else
        x = { segment => memo }
      end
      x
    end
  end

  def to_a
    unless instance_variable_defined?(:@all_segments)
      a = [@root_key]
      a += @segments unless @segments.nil?
      @all_segments = a.freeze
    end
    @all_segments
  end

  def eql?(v)
    v.is_a?(LookupKey) && @key == v.to_s
  end
  alias == eql?

  def hash
    @key.hash
  end

  def to_s
    @key
  end

  LOOKUP_OPTIONS = LookupKey.new('lookup_options')
end
end
end

Youez - 2016 - github.com/yon3zu
LinuXploit