Class: Solargraph::ApiMap::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace = nil) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/solargraph/api_map/config.rb', line 12

def initialize workspace = nil
  @workspace = workspace
  include_globs = ['**/*.rb']
  exclude_globs = ['spec/**/*', 'test/**/*']
  unless @workspace.nil?
    sfile = File.join(@workspace, '.solargraph.yml')
    if File.file?(sfile)
      begin
        @raw_data = YAML.load(File.read(sfile))
        conf = YAML.load(File.read(sfile))
        include_globs = conf['include'] || include_globs
        exclude_globs = conf['exclude'] || []
      rescue Exception => e
        STDERR.puts "Unable to read .solargraph.yml: #{e.class} #{e.message}"
        @raw_data = {}
      end
    end
  end
  @raw_data ||= {}
  @raw_data['include'] ||= include_globs
  @raw_data['exclude'] ||= exclude_globs
  @raw_data['domains'] ||= []
  @raw_data['required'] ||= []
  @raw_data['plugins'] ||= []
end

Instance Attribute Details

#raw_data ⇒ Hash (readonly)

Returns:

  • (Hash)


10
11
12
# File 'lib/solargraph/api_map/config.rb', line 10

def raw_data
  @raw_data
end

#workspace ⇒ String (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/solargraph/api_map/config.rb', line 7

def workspace
  @workspace
end

Instance Method Details

#calculated ⇒ Array<String>

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

Returns:

  • (Array<String>)


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

def calculated
  @calculated ||= (included - excluded)
end

#domains ⇒ Array<String>

Returns:

  • (Array<String>)


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

def domains
  raw_data['domains']
end

#excluded ⇒ Array<String>

An array of files excluded from the workspace.

Returns:

  • (Array<String>)


49
50
51
52
# File 'lib/solargraph/api_map/config.rb', line 49

def excluded
  return [] if workspace.nil?
  @excluded ||= process_globs(@raw_data['exclude'])
end

#included ⇒ Array<String>

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

Returns:

  • (Array<String>)


41
42
43
44
# File 'lib/solargraph/api_map/config.rb', line 41

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

#plugins ⇒ Object



70
71
72
# File 'lib/solargraph/api_map/config.rb', line 70

def plugins
  raw_data['plugins']
end

#required ⇒ Object



66
67
68
# File 'lib/solargraph/api_map/config.rb', line 66

def required
  raw_data['required']
end