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


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

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)

Returns the value of attribute name


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

def name
  @name
end

#name_authorityObject (readonly)

Returns the value of attribute name_authority


6
7
8
# File 'lib/puppet/pops/types/type_set_reference.rb', line 6

def name_authority
  @name_authority
end

#type_setObject (readonly)

Returns the value of attribute type_set


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

def type_set
  @type_set
end

#version_rangeObject (readonly)

Returns the value of attribute version_range


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

def version_range
  @version_range
end

Instance Method Details

#_pcore_init_hashObject


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

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


19
20
21
# File 'lib/puppet/pops/types/type_set_reference.rb', line 19

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

#eql?(o) ⇒ Boolean


23
24
25
# File 'lib/puppet/pops/types/type_set_reference.rb', line 23

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


27
28
29
# File 'lib/puppet/pops/types/type_set_reference.rb', line 27

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

#resolve(loader) ⇒ Object

Raises:

  • (ArgumentError)

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

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


54
55
56
# File 'lib/puppet/pops/types/type_set_reference.rb', line 54

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