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

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

Overview

Each individual option in a case statement.

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #scope

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Branch

#initialize

Methods inherited from Puppet::Parser::AST

associates_doc, #evaluate_match, #initialize, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

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

Instance Attribute Details

#statementsObject

Returns the value of attribute statements.



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

def statements
  @statements
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/vendor/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/vendor/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/vendor/puppet/parser/ast/caseopt.rb', line 12

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

#eachoptObject



40
41
42
43
44
# File 'lib/vendor/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/vendor/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/vendor/puppet/parser/ast/caseopt.rb', line 48

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