Class: Solargraph::Parser::ParserGem::NodeProcessors::StructDefinition::StructDefintionNode
- Inherits:
-
Object
- Object
- Solargraph::Parser::ParserGem::NodeProcessors::StructDefinition::StructDefintionNode
- Defined in:
- lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb
Overview
A node wrapper for a Struct definition via inheritance.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Array<Array(Parser::AST::Node, String)>
- #body_node ⇒ Parser::AST::Node
- #class_name ⇒ String
-
#initialize(node) ⇒ StructDefintionNode
constructor
A new instance of StructDefintionNode.
- #keyword_init? ⇒ Boolean
Constructor Details
#initialize(node) ⇒ StructDefintionNode
Returns a new instance of StructDefintionNode.
54 55 56 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 54 def initialize node @node = node end |
Class Method Details
.match?(node) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 32 def match? node return false unless node&.type == :class struct_definition_node?(node.children[1]) end |
Instance Method Details
#attributes ⇒ Array<Array(Parser::AST::Node, String)>
64 65 66 67 68 69 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 64 def attributes struct_attribute_nodes.map do |struct_def_param| next unless struct_def_param.type == :sym [struct_def_param, struct_def_param.children[0].to_s] end.compact end |
#body_node ⇒ Parser::AST::Node
84 85 86 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 84 def body_node node.children[2] end |
#class_name ⇒ String
59 60 61 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 59 def class_name Parser::NodeMethods.unpack_name(node) end |
#keyword_init? ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb', line 71 def keyword_init? keyword_init_param = struct_attribute_nodes.find do |struct_def_param| struct_def_param.type == :hash && struct_def_param.children[0].type == :pair && struct_def_param.children[0].children[0].children[0] == :keyword_init end return false if keyword_init_param.nil? # rubocop:disable-next Lint/BooleanSymbol keyword_init_param.children[0].children[1].type == :true end |