Class: Puppet::Parser::AST::CaseOpt

Inherits:
Branch show all
Defined in:
lib/puppet/parser/ast/caseopt.rb

Overview

Each individual option in a case statement.

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Instance Method Summary collapse

Methods inherited from Branch

#initialize

Constructor Details

This class inherits a constructor from Puppet::Parser::AST::Branch

Instance Attribute Details

#statementsObject



6
7
8
# File 'lib/puppet/parser/ast/caseopt.rb', line 6

def statements
  @statements
end

#valueObject



6
7
8
# File 'lib/puppet/parser/ast/caseopt.rb', line 6

def value
  @value
end

Instance Method Details

#default?Boolean

Are we the default option?

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet/parser/ast/caseopt.rb', line 17

def default?
  # Cache the @default value.
  return @default if defined?(@default)

  @value.each { |subval|
    if subval.is_a?(AST::Default)
      @default = true
      break
    end
  }

  @default ||= false

  @default
end

#eachObject

CaseOpt is a bit special – we just want the value first, so that CaseStatement can compare, and then it will selectively decide whether to fully evaluate this option



12
13
14
# File 'lib/puppet/parser/ast/caseopt.rb', line 12

def each
  [@value,@statements].each { |child| yield child }
end

#eachoptObject



40
41
42
43
44
# File 'lib/puppet/parser/ast/caseopt.rb', line 40

def eachopt
  @value.each { |subval|
    yield subval
  }
end

#eachvalue(scope) ⇒ Object

You can specify a list of values; return each in turn.



34
35
36
37
38
# File 'lib/puppet/parser/ast/caseopt.rb', line 34

def eachvalue(scope)
  @value.each { |subval|
    yield subval.safeevaluate(scope)
  }
end

#evaluate(scope) ⇒ Object

Evaluate the actual statements; this only gets called if our option matched.



48
49
50
# File 'lib/puppet/parser/ast/caseopt.rb', line 48

def evaluate(scope)
  @statements.safeevaluate(scope)
end