Class: Solargraph::Convention::DataDefinition::NodeProcessors::DataNode

Inherits:
Parser::NodeProcessor::Base show all
Defined in:
lib/solargraph/convention/data_definition.rb

Instance Attribute Summary

Attributes inherited from Parser::NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from Parser::NodeProcessor::Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base

Instance Method Details

#processBoolean

Returns continue processing the next processor of the same node.

Returns:

  • continue processing the next processor of the same node.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/solargraph/convention/data_definition.rb', line 12

def process
  return true if data_definition_node.nil?

  loc = get_node_location(node)
  nspin = Solargraph::Pin::Namespace.new(
    type: :class,
    location: loc,
    closure: region.closure,
    name: data_definition_node.class_name,
    comments: comments_for(node),
    visibility: :public,
    gates: region.closure.gates.freeze
  )
  pins.push nspin

  # define initialize method

  initialize_method_pin = Pin::Method.new(
    name: 'initialize',
    parameters: [],
    scope: :instance,
    location: get_node_location(node),
    closure: nspin,
    visibility: :private,
    comments: comments_for(node)
  )

  # @todo Support both arg and kwarg initializers for Data.define

  # Solargraph::SourceMap::Clip#complete_keyword_parameters does not seem to currently take into account [Pin::Method#signatures] hence we only one for :kwarg

  pins.push initialize_method_pin

  data_definition_node.attributes.map do |attribute_node, attribute_name|
    initialize_method_pin.parameters.push(
      Pin::Parameter.new(
        name: attribute_name,
        decl: :kwarg,
        location: get_node_location(attribute_node),
        closure: initialize_method_pin
      )
    )
  end

  # define attribute readers and instance variables

  data_definition_node.attributes.each do |attribute_node, attribute_name|
    name = attribute_name.to_s
    method_pin = Pin::Method.new(
      name: name,
      parameters: [],
      scope: :instance,
      location: get_node_location(attribute_node),
      closure: nspin,
      comments: attribute_comments(attribute_node, attribute_name),
      visibility: :public
    )

    pins.push method_pin

    pins.push Pin::InstanceVariable.new(name: "@#{attribute_name}",
                                        closure: method_pin,
                                        location: get_node_location(attribute_node),
                                        comments: attribute_comments(attribute_node, attribute_name))
  end

  process_children region.update(closure: nspin, visibility: :public)

  false
end