Class: Bosh::Template::EvaluationLink

Inherits:
Object
  • Object
show all
Includes:
PropertyHelper
Defined in:
lib/bosh/template/evaluation_link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PropertyHelper

#copy_property, #lookup_property, #set_property, #sort_property, #validate_properties_format

Constructor Details

#initialize(instances, properties, instance_group, default_network, deployment_name, root_domain, dns_encoder, use_short_dns) ⇒ EvaluationLink

Returns a new instance of EvaluationLink.



11
12
13
14
15
16
17
18
19
20
# File 'lib/bosh/template/evaluation_link.rb', line 11

def initialize(instances, properties, instance_group, default_network, deployment_name, root_domain, dns_encoder, use_short_dns)
  @instances = instances
  @properties = properties
  @instance_group = instance_group
  @default_network = default_network
  @deployment_name = deployment_name
  @root_domain = root_domain
  @dns_encoder = dns_encoder
  @use_short_dns = use_short_dns
end

Instance Attribute Details

#instancesObject (readonly)

Returns the value of attribute instances.



8
9
10
# File 'lib/bosh/template/evaluation_link.rb', line 8

def instances
  @instances
end

#propertiesObject (readonly)

Returns the value of attribute properties.



9
10
11
# File 'lib/bosh/template/evaluation_link.rb', line 9

def properties
  @properties
end

Instance Method Details

#address(criteria = {}) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bosh/template/evaluation_link.rb', line 45

def address(criteria = {})
  raise NotImplementedError.new('link.address requires bosh director') if @dns_encoder.nil?

  full_criteria = criteria.merge(
    instance_group: @instance_group,
    default_network: @default_network,
    deployment_name: @deployment_name,
    root_domain: @root_domain,
  )

  @dns_encoder.encode_query(full_criteria, @use_short_dns)
end

#if_p(*names) {|values| ... } ⇒ Object

Yields:

  • (values)


34
35
36
37
38
39
40
41
42
43
# File 'lib/bosh/template/evaluation_link.rb', line 34

def if_p(*names)
  values = names.map do |name|
    value = lookup_property(@properties, name)
    return Bosh::Template::EvaluationContext::ActiveElseBlock.new(self) if value.nil?
    value
  end

  yield *values
  Bosh::Template::EvaluationContext::InactiveElseBlock.new
end

#p(*args) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bosh/template/evaluation_link.rb', line 22

def p(*args)
  names = Array(args[0])

  names.each do |name|
    result = lookup_property(@properties, name)
    return result unless result.nil?
  end

  return args[1] if args.length == 2
  raise UnknownProperty.new(names)
end