Class: RSpock::AST::Parser::Block
- Inherits:
-
Object
- Object
- RSpock::AST::Parser::Block
- Includes:
- ASTTransform::TransformationHelper
- Defined in:
- lib/rspock/ast/parser/block.rb
Direct Known Subclasses
CleanupBlock, ExpectBlock, GivenBlock, ThenBlock, WhenBlock, WhereBlock
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#<<(child_node) ⇒ Object
Adds the given
child_nodeto this Block. -
#can_end? ⇒ Boolean
Whether this block can be the last block in a test method.
-
#can_start? ⇒ Boolean
Whether this block can be the first block in a test method.
-
#children ⇒ Array<Parser::AST::Node>
Retrieves the duped array of children AST nodes for this Block.
-
#initialize(type, node) ⇒ Block
constructor
Constructs a new Block.
-
#range ⇒ Parser::Source::Range
Retrieves the Parser::Source::Range for this Block.
-
#succession_error_msg ⇒ String
Retrieves the error message for succession errors.
-
#successors ⇒ Array<Symbol>
Retrieves the valid successors for this Block.
-
#to_rspock_node ⇒ Parser::AST::Node
Converts this Block into an RSpock node.
-
#valid_successor?(block) ⇒ Boolean
Checks whether or not the given
blockis a valid successor for this Block.
Constructor Details
#initialize(type, node) ⇒ Block
Constructs a new Block.
17 18 19 20 21 |
# File 'lib/rspock/ast/parser/block.rb', line 17 def initialize(type, node) @type = type @node = node @children = [] end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
23 24 25 |
# File 'lib/rspock/ast/parser/block.rb', line 23 def node @node end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/rspock/ast/parser/block.rb', line 23 def type @type end |
Instance Method Details
#<<(child_node) ⇒ Object
Adds the given child_node to this Block.
28 29 30 |
# File 'lib/rspock/ast/parser/block.rb', line 28 def <<(child_node) @children << child_node end |
#can_end? ⇒ Boolean
Whether this block can be the last block in a test method.
45 46 47 |
# File 'lib/rspock/ast/parser/block.rb', line 45 def can_end? false end |
#can_start? ⇒ Boolean
Whether this block can be the first block in a test method.
40 41 42 |
# File 'lib/rspock/ast/parser/block.rb', line 40 def can_start? false end |
#children ⇒ Array<Parser::AST::Node>
Retrieves the duped array of children AST nodes for this Block.
59 60 61 |
# File 'lib/rspock/ast/parser/block.rb', line 59 def children @children.dup end |
#range ⇒ Parser::Source::Range
Retrieves the Parser::Source::Range for this Block.
35 36 37 |
# File 'lib/rspock/ast/parser/block.rb', line 35 def range node&.loc&.expression || "?" end |
#succession_error_msg ⇒ String
Retrieves the error message for succession errors.
83 84 85 |
# File 'lib/rspock/ast/parser/block.rb', line 83 def succession_error_msg "Block #{type} @ #{range} must be followed by one of these Blocks: #{successors}" end |
#successors ⇒ Array<Symbol>
Retrieves the valid successors for this Block.
52 53 54 |
# File 'lib/rspock/ast/parser/block.rb', line 52 def successors @successors ||= [].freeze end |
#to_rspock_node ⇒ Parser::AST::Node
Converts this Block into an RSpock node.
66 67 68 69 |
# File 'lib/rspock/ast/parser/block.rb', line 66 def to_rspock_node rspock_type = :"rspock_#{type.downcase}" s(rspock_type, *@children) end |
#valid_successor?(block) ⇒ Boolean
Checks whether or not the given block is a valid successor for this Block.
76 77 78 |
# File 'lib/rspock/ast/parser/block.rb', line 76 def valid_successor?(block) successors.include?(block.type) end |