Class: Solargraph::Bench

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

Overview

A container of source maps and workspace data to be cataloged in an ApiMap.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_maps: [], workspace: Workspace.new, live_map: nil, external_requires: []) ⇒ Bench

Returns a new instance of Bench.

Parameters:

  • source_maps (Array<SourceMap>, Set<SourceMap>) (defaults to: [])
  • workspace (Workspace) (defaults to: Workspace.new)
  • live_map (SourceMap, nil) (defaults to: nil)
  • external_requires (Array<String>, Set<String>) (defaults to: [])


24
25
26
27
28
29
30
31
# File 'lib/solargraph/bench.rb', line 24

def initialize source_maps: [], workspace: Workspace.new, live_map: nil, external_requires: []
  @source_maps = source_maps.to_set
  @workspace = workspace
  @live_map = live_map
  @external_requires = external_requires.reject { |path| workspace.would_require?(path) }
                                        .compact
                                        .to_set
end

Instance Attribute Details

#external_requiresSet<String> (readonly)

Returns:

  • (Set<String>)


18
19
20
# File 'lib/solargraph/bench.rb', line 18

def external_requires
  @external_requires
end

#live_mapSourceMap (readonly)

Returns:



15
16
17
# File 'lib/solargraph/bench.rb', line 15

def live_map
  @live_map
end

#source_mapsSet<SourceMap> (readonly)

Returns:



9
10
11
# File 'lib/solargraph/bench.rb', line 9

def source_maps
  @source_maps
end

#workspaceWorkspace (readonly)

Returns:



12
13
14
# File 'lib/solargraph/bench.rb', line 12

def workspace
  @workspace
end

Instance Method Details

#iceboxSet<SourceMap>

Returns:



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

def icebox
  @icebox ||= (source_maps - [live_map])
end

#source_map_hashHash{String => SourceMap}

Returns:



34
35
36
37
38
# File 'lib/solargraph/bench.rb', line 34

def source_map_hash
  # @todo Work around #to_h bug in current Ruby head (3.5) with #map#to_h
  @source_map_hash ||= source_maps.map { |s| [s.filename, s] }
                                  .to_h
end