Class: Puppet::Pops::Types::TypeSetReference

Inherits:
Object
  • Object
show all
Includes:
Annotatable
Defined in:
lib/puppet/pops/types/type_set_reference.rb

Constant Summary

Constants included from Annotatable

Annotatable::TYPE_ANNOTATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Annotatable

#annotatable_accept, #annotations, #init_annotatable

Constructor Details

#initialize(owner, init_hash) ⇒ TypeSetReference

Returns a new instance of TypeSetReference.



13
14
15
16
17
18
19
# File 'lib/puppet/pops/types/type_set_reference.rb', line 13

def initialize(owner, init_hash)
  @owner = owner
  @name_authority = (init_hash[KEY_NAME_AUTHORITY] || owner.name_authority).freeze
  @name = init_hash[KEY_NAME].freeze
  @version_range = PSemVerRangeType.convert(init_hash[KEY_VERSION_RANGE])
  init_annotatable(init_hash)
end

Instance Attribute Details

#nameObject (readonly)



9
10
11
# File 'lib/puppet/pops/types/type_set_reference.rb', line 9

def name
  @name
end

#name_authorityObject (readonly)



8
9
10
# File 'lib/puppet/pops/types/type_set_reference.rb', line 8

def name_authority
  @name_authority
end

#type_setObject (readonly)



11
12
13
# File 'lib/puppet/pops/types/type_set_reference.rb', line 11

def type_set
  @type_set
end

#version_rangeObject (readonly)



10
11
12
# File 'lib/puppet/pops/types/type_set_reference.rb', line 10

def version_range
  @version_range
end

Instance Method Details

#_pcore_init_hashObject



33
34
35
36
37
38
39
# File 'lib/puppet/pops/types/type_set_reference.rb', line 33

def _pcore_init_hash
  result = super
  result[KEY_NAME_AUTHORITY] = @name_authority unless @name_authority == @owner.name_authority
  result[KEY_NAME] = @name
  result[KEY_VERSION_RANGE] = @version_range.to_s
  result
end

#accept(visitor, guard) ⇒ Object



21
22
23
# File 'lib/puppet/pops/types/type_set_reference.rb', line 21

def accept(visitor, guard)
  annotatable_accept(visitor, guard)
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/puppet/pops/types/type_set_reference.rb', line 25

def eql?(o)
  self.class == o.class && @name_authority.eql?(o.name_authority) && @name.eql?(o.name) && @version_range.eql?(o.version_range)
end

#hashObject



29
30
31
# File 'lib/puppet/pops/types/type_set_reference.rb', line 29

def hash
  [@name_authority, @name, @version_range].hash
end

#resolve(loader) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet/pops/types/type_set_reference.rb', line 41

def resolve(loader)
  typed_name = Loader::TypedName.new(:type, @name, @name_authority)
  loaded_entry = loader.load_typed(typed_name)
  type_set = loaded_entry.nil? ? nil : loaded_entry.value

  raise ArgumentError, "#{self} cannot be resolved" if type_set.nil?
  raise ArgumentError, "#{self} resolves to a #{type_set.name}" unless type_set.is_a?(PTypeSetType)

  @type_set = type_set.resolve(loader)
  unless @version_range.include?(@type_set.version)
    raise ArgumentError, "#{self} resolves to an incompatible version. Expected #{@version_range}, got #{type_set.version}"
  end

  nil
end

#to_sObject



57
58
59
# File 'lib/puppet/pops/types/type_set_reference.rb', line 57

def to_s
  "#{@owner.label} reference to TypeSet named '#{@name}'"
end