Class: Solargraph::Workspace::Config

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

Overview

Configuration data for a workspace.

Constant Summary collapse

MAX_FILES =

The maximum number of files that can be added to a workspace. The workspace’s .solargraph.yml can override this value.

5000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = '') ⇒ Config

Returns a new instance of Config.

Parameters:

  • workspace (String)


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/workspace/config.rb', line 19

def initialize directory = ''
  @directory = directory
  include_globs = ['**/*.rb']
  exclude_globs = ['spec/**/*', 'test/**/*', 'vendor/**/*', '.bundle/**/*']
  unless @directory.empty?
    sfile = File.join(@directory, '.solargraph.yml')
    if File.file?(sfile)
      @raw_data = YAML.safe_load(File.read(sfile))
      include_globs = @raw_data['include'] || include_globs
      exclude_globs = @raw_data['exclude'] || []
    end
  end
  @raw_data ||= {}
  @raw_data['include'] ||= include_globs
  @raw_data['exclude'] ||= exclude_globs
  @raw_data['require'] ||= []
  @raw_data['domains'] ||= []
  @raw_data['reporters'] ||= %w[rubocop require_not_found]
  @raw_data['plugins'] ||= []
  @raw_data['require_paths'] ||= []
  @raw_data['max_files'] ||= MAX_FILES
  included
  excluded
end

Instance Attribute Details

#directoryString (readonly)

Returns:

  • (String)


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

def directory
  @directory
end

#raw_dataHash (readonly)

Returns:

  • (Hash)


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

def raw_data
  @raw_data
end

Instance Method Details

#calculatedArray<String>

The calculated array of (included - excluded) files in the workspace.

Returns:

  • (Array<String>)


63
64
65
# File 'lib/solargraph/workspace/config.rb', line 63

def calculated
  @calculated ||= included - excluded
end

#domainsArray<String>

An array of domains configured for the workspace. A domain is a namespace that the ApiMap should include in the global namespace. It’s typically used to identify available DSLs.

Returns:

  • (Array<String>)


72
73
74
# File 'lib/solargraph/workspace/config.rb', line 72

def domains
  raw_data['domains']
end

#excludedArray<String>

An array of files excluded from the workspace.

Returns:

  • (Array<String>)


55
56
57
58
# File 'lib/solargraph/workspace/config.rb', line 55

def excluded
  return [] if directory.empty?
  @excluded ||= process_exclusions(@raw_data['exclude'])
end

#includedArray<String>

An array of files included in the workspace (before calculating excluded files).

Returns:

  • (Array<String>)


47
48
49
50
# File 'lib/solargraph/workspace/config.rb', line 47

def included
  return [] if directory.empty?
  @included ||= process_globs(@raw_data['include'])
end

#max_filesInteger

The maximum number of files to parse from the workspace.

Returns:

  • (Integer)


107
108
109
# File 'lib/solargraph/workspace/config.rb', line 107

def max_files
  raw_data['max_files']
end

#pluginsArray<String>

An array of Solargraph plugins to install.

Returns:

  • (Array<String>)


93
94
95
# File 'lib/solargraph/workspace/config.rb', line 93

def plugins
  raw_data['plugins']
end

#reportersArray<String>

An array of reporters to use for diagnostics.

Returns:

  • (Array<String>)


100
101
102
# File 'lib/solargraph/workspace/config.rb', line 100

def reporters
  raw_data['reporters']
end

#require_pathsArray<String>

An array of load paths for required paths.

Returns:

  • (Array<String>)


86
87
88
# File 'lib/solargraph/workspace/config.rb', line 86

def require_paths
  raw_data['require_paths'] || []
end

#requiredArray<String>

An array of required paths to add to the workspace.

Returns:

  • (Array<String>)


79
80
81
# File 'lib/solargraph/workspace/config.rb', line 79

def required
  raw_data['require']
end