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: [])


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

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>)


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

def external_requires
  @external_requires
end

#live_mapSourceMap (readonly)

Returns:



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

def live_map
  @live_map
end

#source_mapsSet<SourceMap> (readonly)

Returns:



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

def source_maps
  @source_maps
end

#workspaceWorkspace (readonly)

Returns:



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

def workspace
  @workspace
end

Instance Method Details

#iceboxSet<SourceMap>

Returns:



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

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

#source_map_hashHash{String => SourceMap}

@sg-ignore flow sensitive typing needs better handling of ||= on lvars

Returns:



34
35
36
37
# 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.to_h { |s| [s.filename, s] }
end