Sha256: 181a3b0e5ff8243e38a045f1f72acab43d5e8bfe5e0af6730f0bd43c7d335357

Contents?: true

Size: 1.1 KB

Versions: 40

Compression:

Stored size: 1.1 KB

Contents

module Puppet::Pops
module Loader
# A namespace/name/type combination that can be used as a compound hash key
#
# @api public
class TypedName
  attr_reader :hash
  attr_reader :type
  attr_reader :name_authority
  attr_reader :name
  attr_reader :name_parts
  attr_reader :compound_name

  def initialize(type, name, name_authority = Pcore::RUNTIME_NAME_AUTHORITY)
    name = name.downcase
    @type = type
    @name_authority = name_authority
    # relativize the name (get rid of leading ::), and make the split string available
    parts = name.to_s.split(DOUBLE_COLON)
    if parts[0].empty?
      parts.shift
      @name = name[2..-1]
    else
      @name = name
    end
    @name_parts = parts.freeze

    # Use a frozen compound key for the hash and comparison. Most varying part first
    @compound_name = "#{@name}/#{@type}/#{@name_authority}".freeze
    @hash = @compound_name.hash
    freeze
  end

  def ==(o)
    o.class == self.class && o.compound_name == @compound_name
  end

  alias eql? ==

  def qualified?
    @name_parts.size > 1
  end

  def to_s
    "#{@name_authority}/#{@type}/#{@name}"
  end
end
end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/pops/loader/typed_name.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/pops/loader/typed_name.rb
puppet-4.10.12 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.12-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.12-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.12-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.10.11 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.11-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.11-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.11-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.10.10 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.10-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.10-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.10-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/pops/loader/typed_name.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/pops/loader/typed_name.rb
puppet-4.10.9 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.9-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.9-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.9-universal-darwin lib/puppet/pops/loader/typed_name.rb