Module: Solargraph::Rspec::Util

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

Overview

Utility methods for building pins and references.

Class Method Summary collapse

Class Method Details

.build_location(ast, path) ⇒ Object

Parameters:

  • ast (Parser::AST::Node)


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/solargraph/rspec/util.rb', line 59

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

.build_module_extend(ns, module_name, location) ⇒ Object



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

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



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

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, comments: [], attribute: false, scope: :instance) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solargraph/rspec/util.rb', line 10

def self.build_public_method(
  ns,
  name,
  types: nil,
  location: nil,
  comments: [],
  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



51
52
53
54
55
56
# File 'lib/solargraph/rspec/util.rb', line 51

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



71
72
73
# File 'lib/solargraph/rspec/util.rb', line 71

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