Module: Solargraph::Rspec::PinFactory
- Defined in:
- lib/solargraph/rspec/pin_factory.rb
Overview
Factory class for building pins and references.
Class Method Summary collapse
- .build_location(location_range, path) ⇒ Solargraph::Location
-
.build_location_range(ast) ⇒ Solargraph::Range
Given the following code, Solargraph::Parser.node_range returns the following range for block ast:.
- .build_module_extend(namespace, module_name, location) ⇒ Solargraph::Pin::Reference::Extend
- .build_module_include(namespace, module_name, location) ⇒ Solargraph::Pin::Reference::Include
- .build_public_method(namespace, name, types: nil, location: nil, comments: [], attribute: false, scope: :instance, node: nil) ⇒ Solargraph::Pin::Method
- .dummy_location(path) ⇒ Solargraph::Location
Class Method Details
.build_location(location_range, path) ⇒ Solargraph::Location
113 114 115 116 117 118 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 113 def self.build_location(location_range, path) Solargraph::Location.new( File.(path), location_range ) end |
.build_location_range(ast) ⇒ Solargraph::Range
Given the following code, Solargraph::Parser.node_range returns the following range for block ast:
some_method_with_block do ^ - block start end ^ - block end
Instead we want the range to be:
some_method_with_block do
^ - block start
end ^ - block end
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 94 def self.build_location_range(ast) if ast.type == :block method_range = Solargraph::Parser.node_range(ast.children[0]) full_block_range = Solargraph::Parser.node_range(ast) Solargraph::Range.from_to( method_range.ending.line, method_range.ending.character, full_block_range.ending.line, full_block_range.ending.character ) else Solargraph::Parser.node_range(ast) end end |
.build_module_extend(namespace, module_name, location) ⇒ Solargraph::Pin::Reference::Extend
61 62 63 64 65 66 67 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 61 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
49 50 51 52 53 54 55 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 49 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
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 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 18 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
71 72 73 74 75 76 |
# File 'lib/solargraph/rspec/pin_factory.rb', line 71 def self.dummy_location(path) Solargraph::Location.new( File.(path), Solargraph::Range.from_to(0, 0, 0, 0) ) end |