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.
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, = 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..] 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_name ⇒ Object (readonly)
14 15 16 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 14 def compound_name @compound_name end |
#hash ⇒ Object (readonly)
9 10 11 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 9 def hash @hash end |
#name ⇒ Object (readonly)
12 13 14 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 12 def name @name end |
#name_authority ⇒ Object (readonly)
11 12 13 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 11 def @name_authority end |
#name_parts ⇒ Object (readonly)
13 14 15 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 13 def name_parts @name_parts end |
#type ⇒ Object (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 |
#parent ⇒ Object
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
47 48 49 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 47 def qualified? @name_parts.size > 1 end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/puppet/pops/loader/typed_name.rb', line 51 def to_s "#{@name_authority}/#{@type}/#{@name}" end |