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

Constructor Details

#initialize(instances, properties) ⇒ EvaluationLink

Returns a new instance of EvaluationLink.



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

def initialize(instances, properties)
  @instances = instances
  @properties = properties
end

Instance Attribute Details

#instancesObject (readonly)

Returns the value of attribute instances.



6
7
8
# File 'lib/bosh/template/evaluation_link.rb', line 6

def instances
  @instances
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

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

Yields:

  • (values)


26
27
28
29
30
31
32
33
34
35
# File 'lib/bosh/template/evaluation_link.rb', line 26

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:



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bosh/template/evaluation_link.rb', line 14

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