Class: Solargraph::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/repo.rb

Overview

A repository for the gems available in the specified directory. If the directory has a Gemfile, Repo will use its gem definitions. Otherwise it uses the system gems.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Repo

Returns a new instance of Repo.

Parameters:

  • directory (String, nil)


16
17
18
19
# File 'lib/solargraph/repo.rb', line 16

def initialize directory
  @directory = File.expand_path(directory) if directory
  build_from_directory
end

Instance Attribute Details

#directory ⇒ String? (readonly)

Returns:

  • (String, nil)


13
14
15
# File 'lib/solargraph/repo.rb', line 13

def directory
  @directory
end

Instance Method Details

#bundled ⇒ Array<Solargraph::Metagem>

Metagems from the directory's bundle definition, or an empty array if a bundle definition does not exist.

Returns:



68
69
70
# File 'lib/solargraph/repo.rb', line 68

def bundled
  @metagems || []
end

#bundled? ⇒ Boolean Also known as: bundle?

Note:

If Solargraph itself is running in this directory's bundled environment, bundled? is false.

True if the directory has a bundle definition.

Returns:

  • (Boolean)


59
60
61
# File 'lib/solargraph/repo.rb', line 59

def bundled?
  !!@metagems
end

#find_by_group(group) ⇒ Array<Metagem>

Get an array of metagems by its bundle group name. Returns an empty array if the repo isn't bundled or the group doesn't exist.

Parameters:

  • group (Symbol)

Returns:



48
49
50
51
52
# File 'lib/solargraph/repo.rb', line 48

def find_by_group group
  return system_find_by_group(group) unless bundled?

  bundled_group_map[group] || []
end

#find_by_name(name) ⇒ Metagem?

Find a metagem by name from the directory's bundle definition or the system gems.

Parameters:

  • name (String)

Returns:



37
38
39
40
41
# File 'lib/solargraph/repo.rb', line 37

def find_by_name name
  return system_find_by_name(name) unless bundled?

  bundled_metagem_name_map[name]
end

#find_by_path(path) ⇒ Metagem?

Find a metagem by path from the directory's bundle definition or the system gems.

Parameters:

  • path (String)

Returns:



26
27
28
29
30
# File 'lib/solargraph/repo.rb', line 26

def find_by_path path
  return system_find_by_path(path) unless bundled?

  bundled_metagem_path_map[path]
end