Sha256: 81db87d5887277f87b192665f26b43e1e8478f4ea5991d3061c306716bbea0e5

Contents?: true

Size: 1.08 KB

Versions: 28

Compression:

Stored size: 1.08 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)
    @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

28 entries across 28 versions & 1 rubygems

Version Path
puppet-4.10.1 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.1-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.1-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.1-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.10.0 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.0-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.0-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.10.0-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.9.4 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.4-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.4-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.4-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.9.3 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.3-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.3-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.3-universal-darwin lib/puppet/pops/loader/typed_name.rb
puppet-4.9.2 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.2-x86-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.2-x64-mingw32 lib/puppet/pops/loader/typed_name.rb
puppet-4.9.2-universal-darwin lib/puppet/pops/loader/typed_name.rb