Class: Solargraph::Convention::StructDefinition::StructAssignmentNode

Inherits:
StructDefintionNode show all
Defined in:
lib/solargraph/convention/struct_definition/struct_assignment_node.rb

Overview

A node wrapper for a Struct definition via const assignment.

Examples:

MyStruct = Struct.new(:bar, :baz) do
  def foo
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StructDefintionNode

#attributes, #body_node, #initialize, #keyword_init?

Constructor Details

This class inherits a constructor from Solargraph::Convention::StructDefinition::StructDefintionNode

Class Method Details

.valid?(node) ⇒ Boolean

s(:casgn, nil, :Foo,

s(:block,
  s(:send,
    s(:const, nil, :Struct), :new,
    s(:sym, :bar),
    s(:sym, :baz)),
  s(:args),
  s(:def, :foo,
    s(:args),
    s(:send, nil, :bar))))

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/solargraph/convention/struct_definition/struct_assignment_node.rb', line 25

def valid?(node)
  return false unless node&.type == :casgn
  return false if node.children[2].nil?
  struct_node = node.children[2].children[0]

  struct_definition_node?(struct_node)
end

Instance Method Details

#class_nameObject



34
35
36
37
38
39
40
# File 'lib/solargraph/convention/struct_definition/struct_assignment_node.rb', line 34

def class_name
  if node.children[0]
    Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
  else
    node.children[1].to_s
  end
end