Module: Solargraph::Rails::Util

Defined in:
lib/solargraph/rails/util.rb

Class Method Summary collapse

Class Method Details

.build_location(ast, path) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/solargraph/rails/util.rb', line 51

def self.build_location(ast, path)
  Solargraph::Location.new(
    File.expand_path(path),
    Solargraph::Range.from_to(
      ast.location.first_line,
      0,
      ast.location.last_line,
      ast.location.column
    )
  )
end

.build_module_extend(ns, module_name, location) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/solargraph/rails/util.rb', line 36

def self.build_module_extend(ns, module_name, location)
  Solargraph::Pin::Reference::Extend.new(
    closure: ns,
    name: module_name,
    location: location
  )
end

.build_module_include(ns, module_name, location) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/solargraph/rails/util.rb', line 28

def self.build_module_include(ns, module_name, location)
  Solargraph::Pin::Reference::Include.new(
    closure: ns,
    name: module_name,
    location: location
  )
end

.build_public_method(ns, name, types: nil, location: nil, attribute: false, scope: :instance) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/solargraph/rails/util.rb', line 4

def self.build_public_method(
  ns,
  name,
  types: nil,
  location: nil,
  attribute: false,
  scope: :instance
)
  opts = {
    name: name,
    location: location,
    closure: ns,
    scope: scope,
    attribute: attribute
  }

  comments = []
  comments << "@return [#{types.join(',')}]" if types

  opts[:comments] = comments.join("\n")

  Solargraph::Pin::Method.new(**opts)
end

.dummy_location(path) ⇒ Object



44
45
46
47
48
49
# File 'lib/solargraph/rails/util.rb', line 44

def self.dummy_location(path)
  Solargraph::Location.new(
    File.expand_path(path),
    Solargraph::Range.from_to(0, 0, 0, 0)
  )
end

.method_return(path, type) ⇒ Object



63
64
65
# File 'lib/solargraph/rails/util.rb', line 63

def self.method_return(path, type)
  Solargraph::Pin::Reference::Override.method_return(path, type)
end