Class: Solargraph::Workspace
- Inherits:
-
Object
- Object
- Solargraph::Workspace
- Defined in:
- lib/solargraph/workspace.rb,
lib/solargraph/workspace/config.rb
Overview
A workspace consists of the files in a project’s directory and the project’s configuration. It provides a Source for each file to be used in an associated Library or ApiMap.
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
- #directory ⇒ String readonly
- #gemnames ⇒ Array<String> readonly
-
#require_paths ⇒ Array<String>
readonly
The require paths associated with the workspace.
Instance Method Summary collapse
- #config ⇒ Solargraph::Workspace::Config
- #filenames ⇒ Array<String>
-
#gemspec? ⇒ Boolean
True if the workspace contains at least one gemspec file.
-
#gemspecs ⇒ Array<String>
Get an array of all gemspec files in the workspace.
- #has_file?(filename) ⇒ Boolean
-
#initialize(directory = '', config = nil) ⇒ Workspace
constructor
A new instance of Workspace.
-
#merge(source) ⇒ Boolean
Merge the source.
-
#remove(filename) ⇒ Boolean
Remove a source from the workspace.
-
#source(filename) ⇒ Solargraph::Source
Get a source by its filename.
- #sources ⇒ Array<Solargraph::Source>
-
#synchronize!(updater) ⇒ void
Synchronize the workspace from the provided updater.
-
#would_merge?(filename) ⇒ Boolean
Determine whether a file would be merged into the workspace.
-
#would_require?(path) ⇒ Boolean
True if the path resolves to a file in the workspace’s require paths.
Constructor Details
#initialize(directory = '', config = nil) ⇒ Workspace
Returns a new instance of Workspace.
24 25 26 27 28 29 30 31 |
# File 'lib/solargraph/workspace.rb', line 24 def initialize directory = '', config = nil @directory = directory @config = config load_sources @gemnames = [] @require_paths = generate_require_paths require_plugins end |
Instance Attribute Details
#directory ⇒ String (readonly)
12 13 14 |
# File 'lib/solargraph/workspace.rb', line 12 def directory @directory end |
#gemnames ⇒ Array<String> (readonly)
20 21 22 |
# File 'lib/solargraph/workspace.rb', line 20 def gemnames @gemnames end |
#require_paths ⇒ Array<String> (readonly)
The require paths associated with the workspace.
17 18 19 |
# File 'lib/solargraph/workspace.rb', line 17 def require_paths @require_paths end |
Instance Method Details
#config ⇒ Solargraph::Workspace::Config
34 35 36 |
# File 'lib/solargraph/workspace.rb', line 34 def config @config ||= Solargraph::Workspace::Config.new(directory) end |
#filenames ⇒ Array<String>
76 77 78 |
# File 'lib/solargraph/workspace.rb', line 76 def filenames source_hash.keys end |
#gemspec? ⇒ Boolean
True if the workspace contains at least one gemspec file.
113 114 115 |
# File 'lib/solargraph/workspace.rb', line 113 def gemspec? !gemspecs.empty? end |
#gemspecs ⇒ Array<String>
Get an array of all gemspec files in the workspace.
120 121 122 123 124 125 |
# File 'lib/solargraph/workspace.rb', line 120 def gemspecs return [] if directory.empty? || directory == '*' @gemspecs ||= Dir[File.join(directory, '**/*.gemspec')].select do |gs| config.allow? gs end end |
#has_file?(filename) ⇒ Boolean
87 88 89 |
# File 'lib/solargraph/workspace.rb', line 87 def has_file? filename source_hash.key?(filename) end |
#merge(source) ⇒ Boolean
Merge the source. A merge will update the existing source for the file or add it to the sources if the workspace is configured to include it. The source is ignored if the configuration excludes it.
44 45 46 47 48 49 50 51 52 |
# File 'lib/solargraph/workspace.rb', line 44 def merge source unless directory == '*' || source_hash.key?(source.filename) # Reload the config to determine if a new source should be included @config = Solargraph::Workspace::Config.new(directory) return false unless config.calculated.include?(source.filename) end source_hash[source.filename] = source true end |
#remove(filename) ⇒ Boolean
Remove a source from the workspace. The source will not be removed if its file exists and the workspace is configured to include it.
69 70 71 72 73 |
# File 'lib/solargraph/workspace.rb', line 69 def remove filename return false unless source_hash.key?(filename) source_hash.delete filename true end |
#source(filename) ⇒ Solargraph::Source
Get a source by its filename.
95 96 97 |
# File 'lib/solargraph/workspace.rb', line 95 def source filename source_hash[filename] end |
#sources ⇒ Array<Solargraph::Source>
81 82 83 |
# File 'lib/solargraph/workspace.rb', line 81 def sources source_hash.values end |
#synchronize!(updater) ⇒ void
This method returns an undefined value.
Synchronize the workspace from the provided updater.
131 132 133 |
# File 'lib/solargraph/workspace.rb', line 131 def synchronize! updater source_hash[updater.filename] = source_hash[updater.filename].synchronize(updater) end |
#would_merge?(filename) ⇒ Boolean
Determine whether a file would be merged into the workspace.
58 59 60 61 62 |
# File 'lib/solargraph/workspace.rb', line 58 def would_merge? filename return true if directory == '*' || source_hash.include?(filename) @config = Solargraph::Workspace::Config.new(directory) config.calculated.include?(filename) end |
#would_require?(path) ⇒ Boolean
True if the path resolves to a file in the workspace’s require paths.
103 104 105 106 107 108 |
# File 'lib/solargraph/workspace.rb', line 103 def would_require? path require_paths.each do |rp| return true if File.exist?(File.join(rp, "#{path}.rb")) end false end |