Class: LanguageServer::Project::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/project/node.rb

Direct Known Subclasses

ConstPathRef, Constant, LiteralValue, Module, VarRef

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attribute_namesObject



17
18
19
# File 'lib/language_server/project/node.rb', line 17

def attribute_names
  @attribute_names ||= superclass.respond_to?(:attribute_names) ? superclass.attribute_names.dup : []
end

.attributes(*attrs) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/language_server/project/node.rb', line 5

def attributes(*attrs)
  attr_accessor(*attrs)
  attribute_names.concat(attrs)
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
def initialize(#{attribute_names.map { |n| "#{n}:" }.join(",")})
  #{attribute_names.map { |n|
      "@#{n} = #{n}"
    }.join("\n")}
end
  RUBY
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/language_server/project/node.rb', line 36

def ==(other)
  eql?(other)
end

#attributesObject



44
45
46
47
48
# File 'lib/language_server/project/node.rb', line 44

def attributes
  self.class.attribute_names.map { |a|
    [a, public_send(a)]
  }.to_h
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/language_server/project/node.rb', line 32

def eql?(other)
  other.instance_of?(self.class) && attributes == other.attributes
end

#hashObject



40
41
42
# File 'lib/language_server/project/node.rb', line 40

def hash
  self.attributes.hash
end

#local_pathObject



28
29
30
# File 'lib/language_server/project/node.rb', line 28

def local_path
  path.local_path
end

#remote_pathObject



24
25
26
# File 'lib/language_server/project/node.rb', line 24

def remote_path
  path.remote_path
end