Class: Puppet::Pops::Loader::TypedName

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/loader/typed_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, name_authority = Pcore::RUNTIME_NAME_AUTHORITY) ⇒ TypedName

Returns a new instance of TypedName.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/pops/loader/typed_name.rb', line 14

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

Instance Attribute Details

#compound_nameObject (readonly)



12
13
14
# File 'lib/puppet/pops/loader/typed_name.rb', line 12

def compound_name
  @compound_name
end

#hashObject (readonly)



7
8
9
# File 'lib/puppet/pops/loader/typed_name.rb', line 7

def hash
  @hash
end

#nameObject (readonly)



10
11
12
# File 'lib/puppet/pops/loader/typed_name.rb', line 10

def name
  @name
end

#name_authorityObject (readonly)



9
10
11
# File 'lib/puppet/pops/loader/typed_name.rb', line 9

def name_authority
  @name_authority
end

#name_partsObject (readonly)



11
12
13
# File 'lib/puppet/pops/loader/typed_name.rb', line 11

def name_parts
  @name_parts
end

#typeObject (readonly)



8
9
10
# File 'lib/puppet/pops/loader/typed_name.rb', line 8

def type
  @type
end

Instance Method Details

#==(o) ⇒ Object Also known as: eql?



34
35
36
# File 'lib/puppet/pops/loader/typed_name.rb', line 34

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

#parentObject

Returns the parent of this instance, or nil if this instance is not qualified.

Returns:

  • the parent of this instance, or nil if this instance is not qualified



41
42
43
# File 'lib/puppet/pops/loader/typed_name.rb', line 41

def parent
  @name_parts.size > 1 ? self.class.new(@type, @name_parts[0...-1].join(DOUBLE_COLON), @name_authority) : nil
end

#qualified?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/puppet/pops/loader/typed_name.rb', line 45

def qualified?
  @name_parts.size > 1
end

#to_sObject



49
50
51
# File 'lib/puppet/pops/loader/typed_name.rb', line 49

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