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

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

Constant Summary collapse

DOUBLE_COLON =
'::'.freeze

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.



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

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

Instance Attribute Details

#compound_nameObject (readonly)



14
15
16
# File 'lib/puppet/pops/loader/typed_name.rb', line 14

def compound_name
  @compound_name
end

#hashObject (readonly)



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

def hash
  @hash
end

#nameObject (readonly)



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

def name
  @name
end

#name_authorityObject (readonly)



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

def name_authority
  @name_authority
end

#name_partsObject (readonly)



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

def name_parts
  @name_parts
end

#typeObject (readonly)



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

def type
  @type
end

Instance Method Details

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



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

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

#qualified?Boolean

Returns:

  • (Boolean)


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

def qualified?
  @name_parts.size > 1
end

#to_sObject



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

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