Module: Solargraph::Rspec::PinFactory

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

Overview

Factory class for building pins and references.

Class Method Summary collapse

Class Method Details

.build_location(location_range, path) ⇒ Solargraph::Location

Parameters:

  • location_range (Solargraph::Range)
  • path (String)

Returns:

  • (Solargraph::Location)


92
93
94
95
96
97
# File 'lib/solargraph/rspec/pin_factory.rb', line 92

def self.build_location(location_range, path)
  Solargraph::Location.new(
    File.expand_path(path),
    location_range
  )
end

.build_location_range(ast) ⇒ Solargraph::Range

Parameters:

  • ast (RubyVM::AbstractSyntaxTree::Node)

Returns:

  • (Solargraph::Range)

See Also:

  • - for why we need -1 for lineno


80
81
82
83
84
85
86
87
# File 'lib/solargraph/rspec/pin_factory.rb', line 80

def self.build_location_range(ast)
  Solargraph::Range.from_to(
    ast.first_lineno - 1,
    ast.first_column,
    ast.last_lineno - 1,
    ast.last_column
  )
end

.build_module_extend(namespace, module_name, location) ⇒ Solargraph::Pin::Reference::Extend

Parameters:

  • namespace (Solargraph::Pin::Namespace)
  • module_name (String)
  • location (Solargraph::Location)

Returns:

  • (Solargraph::Pin::Reference::Extend)


60
61
62
63
64
65
66
# File 'lib/solargraph/rspec/pin_factory.rb', line 60

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

.build_module_include(namespace, module_name, location) ⇒ Solargraph::Pin::Reference::Include

Parameters:

  • namespace (Solargraph::Pin::Namespace)
  • name (String)
  • location (Solargraph::Location)

Returns:

  • (Solargraph::Pin::Reference::Include)


48
49
50
51
52
53
54
# File 'lib/solargraph/rspec/pin_factory.rb', line 48

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

.build_public_method(namespace, name, types: nil, location: nil, comments: [], attribute: false, scope: :instance, node: nil) ⇒ Solargraph::Pin::Method

Parameters:

  • namespace (Solargraph::Pin::Namespace)
  • name (String)
  • types (Array<String>) (defaults to: nil)
  • location (Solargraph::Location) (defaults to: nil)
  • comments (Array<String>) (defaults to: [])
  • attribute (Boolean) (defaults to: false)
  • scope (:instance, :class) (defaults to: :instance)

Returns:

  • (Solargraph::Pin::Method)


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
# File 'lib/solargraph/rspec/pin_factory.rb', line 17

def self.build_public_method(
  namespace,
  name,
  types: nil,
  location: nil,
  comments: [],
  attribute: false,
  scope: :instance,
  node: nil
)
  opts = {
    name: name,
    location: location,
    closure: namespace,
    scope: scope,
    attribute: attribute,
    comments: [],
    node: node
  }

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

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

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

.dummy_location(path) ⇒ Solargraph::Location

Parameters:

  • path (String)

Returns:

  • (Solargraph::Location)


70
71
72
73
74
75
# File 'lib/solargraph/rspec/pin_factory.rb', line 70

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