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.



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

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..]
  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}"
  @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?



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

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



43
44
45
# File 'lib/puppet/pops/loader/typed_name.rb', line 43

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)


47
48
49
# File 'lib/puppet/pops/loader/typed_name.rb', line 47

def qualified?
  @name_parts.size > 1
end

#to_sObject



51
52
53
# File 'lib/puppet/pops/loader/typed_name.rb', line 51

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