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

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)



141
142
143
# File 'lib/puppet/pops/loader/loader.rb', line 141

def name
  @name
end

#name_partsObject (readonly)



142
143
144
# File 'lib/puppet/pops/loader/loader.rb', line 142

def name_parts
  @name_parts
end

#qualifiedObject (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

#typeObject (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

#hashObject



165
166
167
# File 'lib/puppet/pops/loader/loader.rb', line 165

def hash
  @hash
end

#to_sObject



175
176
177
# File 'lib/puppet/pops/loader/loader.rb', line 175

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