Class: Foxtail::Syntax::Parser::AST::Resource

Inherits:
SyntaxNode show all
Defined in:
lib/foxtail/syntax/parser/ast/resource.rb

Overview

Represents a Fluent resource containing messages, terms, and comments This is the root node of a parsed Fluent file

Instance Attribute Summary collapse

Attributes inherited from SyntaxNode

#span

Attributes inherited from BaseNode

#type

Instance Method Summary collapse

Methods inherited from SyntaxNode

#add_span

Methods inherited from BaseNode

#==, #accept, #to_h

Constructor Details

#initialize(body = []) ⇒ Resource

Returns a new instance of Resource.



12
13
14
15
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 12

def initialize(body=[])
  super()
  @body = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 10

def body
  @body
end

Instance Method Details

#childrenObject



17
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 17

def children = body

#each_entry {|Message, Term| ... } ⇒ Enumerator, self

Iterate over Message and Term entries (excludes comments and junk)

Yields:

Returns:

  • (Enumerator)

    if no block given

  • (self)

    if block given



45
46
47
48
49
50
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 45

def each_entry(&block)
  return enum_for(__method__) unless block

  body.each {|entry| yield(entry) if entry.is_a?(Message) || entry.is_a?(Term) }
  self
end

#each_message {|Message| ... } ⇒ Enumerator, self

Iterate over Message entries only

Yields:

Returns:

  • (Enumerator)

    if no block given

  • (self)

    if block given



23
24
25
26
27
28
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 23

def each_message(&block)
  return enum_for(__method__) unless block

  body.each {|entry| yield(entry) if entry.is_a?(Message) }
  self
end

#each_term {|Term| ... } ⇒ Enumerator, self

Iterate over Term entries only

Yields:

  • (Term)

    each term entry

Returns:

  • (Enumerator)

    if no block given

  • (self)

    if block given



34
35
36
37
38
39
# File 'lib/foxtail/syntax/parser/ast/resource.rb', line 34

def each_term(&block)
  return enum_for(__method__) unless block

  body.each {|entry| yield(entry) if entry.is_a?(Term) }
  self
end