Class: Solargraph::External

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

Overview

TODO:

This class might need a way to track changes to the repo, e.g., bundle or dependency updates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, requires, extra_gem_names = []) ⇒ External

Returns a new instance of External.

Parameters:

  • directory (String)
  • requires (Array<String>)
  • extra_gem_names (Array<String>) (defaults to: [])


21
22
23
24
25
26
27
# File 'lib/solargraph/external.rb', line 21

def initialize directory, requires, extra_gem_names = []
  @repo = Repo.new(directory)
  @directory = directory
  @requires = requires
  @extra_gem_names = extra_gem_names
  update!
end

Instance Attribute Details

#directory ⇒ String (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/solargraph/external.rb', line 11

def directory
  @directory
end

#extra_gem_names ⇒ Object (readonly)

Returns the value of attribute extra_gem_names.



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

def extra_gem_names
  @extra_gem_names
end

#requires ⇒ Array<String> (readonly)

Returns:

  • (Array<String>)


14
15
16
# File 'lib/solargraph/external.rb', line 14

def requires
  @requires
end

Instance Method Details

#configured_gem_names ⇒ Object



29
30
31
# File 'lib/solargraph/external.rb', line 29

def configured_gem_names
  loaded_gems.map(&:name) + unloaded_gems.map(&:name) + extra_gem_names
end

#generation ⇒ Integer

Returns incremented whenever the external pin set is rebuilt.

Returns:

  • (Integer) —

    incremented whenever the external pin set is rebuilt



62
63
64
# File 'lib/solargraph/external.rb', line 62

def generation
  @generation ||= 0
end

#loaded_gems ⇒ Object



41
42
43
# File 'lib/solargraph/external.rb', line 41

def loaded_gems
  @loaded_gems ||= Set.new
end

#loaded_stdlibs ⇒ Object



53
54
55
# File 'lib/solargraph/external.rb', line 53

def loaded_stdlibs
  @loaded_stdlibs ||= Set.new
end

#pins ⇒ Object



57
58
59
# File 'lib/solargraph/external.rb', line 57

def pins
  @pins ||= []
end

#rbs_collection_config_path ⇒ String?

Returns:

  • (String, nil)


83
84
85
86
87
88
89
# File 'lib/solargraph/external.rb', line 83

def rbs_collection_config_path
  # @todo Get rid of the '*' case
  @rbs_collection_config_path ||= unless directory.nil? || directory.empty? || directory == '*'
                                    yaml_file = File.join(directory, 'rbs_collection.yaml')
                                    yaml_file if File.file?(yaml_file)
                                  end
end

#rbs_collection_paths ⇒ Array<String>

Returns:

  • (Array<String>)


78
79
80
# File 'lib/solargraph/external.rb', line 78

def rbs_collection_paths
  @rbs_collection_paths ||= read_rbs_collection_paths
end

#unfound_gem_names ⇒ Object



49
50
51
# File 'lib/solargraph/external.rb', line 49

def unfound_gem_names
  @unfound_gem_names ||= []
end

#unloaded_gems ⇒ Object



45
46
47
# File 'lib/solargraph/external.rb', line 45

def unloaded_gems
  @unloaded_gems ||= Set.new
end

#unresolved_dependencies ⇒ Object



37
38
39
# File 'lib/solargraph/external.rb', line 37

def unresolved_dependencies
  @unresolved_dependencies ||= []
end

#unresolved_requires ⇒ Object



33
34
35
# File 'lib/solargraph/external.rb', line 33

def unresolved_requires
  @unresolved_requires ||= []
end

#update(new_requires, new_gem_names = []) ⇒ Boolean

Parameters:

  • new_requires (Array<String>)

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
# File 'lib/solargraph/external.rb', line 68

def update new_requires, new_gem_names = []
  return false if requires == new_requires && new_gem_names == extra_gem_names && !cache_changed?

  requires.replace new_requires
  extra_gem_names.replace new_gem_names
  update!
  true
end