Class: Puppet::Pops::Loader::Loader::TypedName
- Defined in:
- lib/puppet/pops/loader/loader.rb
Overview
A name/type combination that can be used as a compound hash key
Instance Attribute Summary collapse
- #name ⇒ Object readonly
- #name_parts ⇒ Object readonly
-
#qualified ⇒ Object
readonly
True if name is qualified (more than a single segment).
- #type ⇒ Object readonly
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(type, name) ⇒ TypedName
constructor
A new instance of TypedName.
- #to_s ⇒ Object
Constructor Details
#initialize(type, name) ⇒ TypedName
Returns a new instance of TypedName.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/puppet/pops/loader/loader.rb', line 147 def initialize(type, name) @type = type # relativize the name (get rid of leading ::), and make the split string available @name_parts = name.to_s.split(/::/) @name_parts.shift if name_parts[0].empty? @name = name_parts.join('::') @qualified = name_parts.size > 1 # precompute hash - the name is frozen, so this is safe to do @hash = [self.class, type, @name].hash # Not allowed to have numeric names - 0, 010, 0x10, 1.2 etc if Puppet::Pops::Utils.is_numeric?(@name) raise ArgumentError, "Illegal attempt to use a numeric name '#{name}' at #{origin_label(origin)}." end freeze() end |
Instance Attribute Details
#name ⇒ Object (readonly)
141 142 143 |
# File 'lib/puppet/pops/loader/loader.rb', line 141 def name @name end |
#name_parts ⇒ Object (readonly)
142 143 144 |
# File 'lib/puppet/pops/loader/loader.rb', line 142 def name_parts @name_parts end |
#qualified ⇒ Object (readonly)
True if name is qualified (more than a single segment)
145 146 147 |
# File 'lib/puppet/pops/loader/loader.rb', line 145 def qualified @qualified end |
#type ⇒ Object (readonly)
140 141 142 |
# File 'lib/puppet/pops/loader/loader.rb', line 140 def type @type end |
Instance Method Details
#==(o) ⇒ Object Also known as: eql?
169 170 171 |
# File 'lib/puppet/pops/loader/loader.rb', line 169 def ==(o) o.class == self.class && type == o.type && name == o.name end |
#to_s ⇒ Object
175 176 177 |
# File 'lib/puppet/pops/loader/loader.rb', line 175 def to_s "#{type}/#{name}" end |