Class: Solargraph::Convention::StructDefinition::StructDefintionNode
- Inherits:
-
Object
- Object
- Solargraph::Convention::StructDefinition::StructDefintionNode
- Defined in:
- lib/solargraph/convention/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.
52 53 54 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 52 def initialize(node) @node = node end |
Class Method Details
.match?(node) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 30 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)>
62 63 64 65 66 67 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 62 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
81 82 83 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 81 def body_node node.children[2] end |
#class_name ⇒ String
57 58 59 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 57 def class_name Parser::NodeMethods.unpack_name(node) end |
#keyword_init? ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/solargraph/convention/struct_definition/struct_definition_node.rb', line 69 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? keyword_init_param.children[0].children[1].type == :true end |