Class: Puppet::Pops::Loader::TypedName
- Defined in:
- lib/puppet/pops/loader/typed_name.rb
Instance Attribute Summary collapse
- #compound_name ⇒ Object readonly
- #hash ⇒ Object readonly
- #name ⇒ Object readonly
- #name_authority ⇒ Object readonly
- #name_parts ⇒ Object readonly
- #type ⇒ Object readonly
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
-
#initialize(type, name, name_authority = Pcore::RUNTIME_NAME_AUTHORITY) ⇒ TypedName
constructor
A new instance of TypedName.
-
#parent ⇒ Object
The parent of this instance, or nil if this instance is not qualified.
- #qualified? ⇒ Boolean
- #to_s ⇒ Object
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, = Pcore::RUNTIME_NAME_AUTHORITY) name = name.downcase @type = type @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_name ⇒ Object (readonly)
12 13 14 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 12 def compound_name @compound_name end |
#hash ⇒ Object (readonly)
7 8 9 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 7 def hash @hash end |
#name ⇒ Object (readonly)
10 11 12 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 10 def name @name end |
#name_authority ⇒ Object (readonly)
9 10 11 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 9 def @name_authority end |
#name_parts ⇒ Object (readonly)
11 12 13 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 11 def name_parts @name_parts end |
#type ⇒ Object (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 |
#parent ⇒ Object
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
45 46 47 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 45 def qualified? @name_parts.size > 1 end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 49 def to_s "#{@name_authority}/#{@type}/#{@name}" end |