Module: YardSequel::AstNodeHash

Defined in:
lib/yard-sequel/ast_node_hash.rb

Overview

Offers methods to convert an Abstract Syntax Tree of a Hash literal or named method parameters to a Hash consisting of YARD::Parser::Ruby::AstNodes.

Author:

  • Kai Moschcau

Class Method Summary collapse

Class Method Details

.check_ast(ast) ⇒ Object

Checks the passed AstNode for validity. If the AstNode is valid, this method does not raise an error.

Raises:

  • (TypeError, ArgumentError)

    If the AstNode is not valid.


24
25
26
27
28
29
30
31
# File 'lib/yard-sequel/ast_node_hash.rb', line 24

def check_ast(ast)
  check_is_ast_node ast
  check_is_hash_or_list ast
  case ast.type
  when :hash then check_hash_children ast
  when :list then check_list_children ast
  end
end

.from_ast(ast) ⇒ Hash<YARD::Parser::Ruby::AstNode>

Creates a new Hash from the passed AstNode. This is the main method to use, to create a new Hash.

Raises:

  • (TypeError, ArgumentError)

    If the AstNode is not valid.


14
15
16
17
# File 'lib/yard-sequel/ast_node_hash.rb', line 14

def from_ast(ast)
  check_ast ast
  node_hash_from_node ast
end