Class: Bundler::Codegraph::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/codegraph/config.rb

Overview

Runtime configuration, driven entirely by environment variables so that a single bundle install can be run with indexing off without editing a file.

Constant Summary collapse

ENV_ENABLED =
'BUNDLER_CODEGRAPH'
ENV_EXCLUDE =
'BUNDLER_CODEGRAPH_EXCLUDE'
ENV_BINARY =
'BUNDLER_CODEGRAPH_BIN'
DEFAULT_BINARY =
'codegraph'
DISABLED_VALUES =
%w[0 off false no].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV) ⇒ Config

Returns a new instance of Config.

Parameters:

  • env (Hash) (defaults to: ENV) —

    environment to read the configuration from



20
21
22
23
24
25
26
27
# File 'lib/bundler/codegraph/config.rb', line 20

def initialize(env: ENV)
  @env                 = env
  @disabled            = DISABLED_VALUES.include?(env[ENV_ENABLED].to_s.strip.downcase)
  @exclude_patterns    = env[ENV_EXCLUDE].to_s.split(',').map(&:strip).reject(&:empty?)
  @binary              = env[ENV_BINARY].to_s.empty? ? DEFAULT_BINARY : env[ENV_BINARY]
  @executable          = nil
  @executable_resolved = false
end

Instance Attribute Details

#binary ⇒ Object (readonly)

Returns the value of attribute binary.



17
18
19
# File 'lib/bundler/codegraph/config.rb', line 17

def binary
  @binary
end

#env ⇒ Object (readonly)

Returns the value of attribute env.



17
18
19
# File 'lib/bundler/codegraph/config.rb', line 17

def env
  @env
end

#exclude_patterns ⇒ Object (readonly)

Returns the value of attribute exclude_patterns.



17
18
19
# File 'lib/bundler/codegraph/config.rb', line 17

def exclude_patterns
  @exclude_patterns
end

Instance Method Details

#disabled? ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bundler/codegraph/config.rb', line 40

def disabled?
  @disabled
end

#excluded?(gem_name) ⇒ Boolean

Returns true when the gem matches one of the exclusion globs.

Parameters:

  • gem_name (String) —

    name of the gem about to be indexed

Returns:

  • (Boolean) —

    true when the gem matches one of the exclusion globs



46
47
48
# File 'lib/bundler/codegraph/config.rb', line 46

def excluded?(gem_name)
  exclude_patterns.any? { |pattern| File.fnmatch?(pattern, gem_name.to_s) }
end

#executable ⇒ String?

Resolved lazily, once: the PATH lookup only runs when something actually needs the binary.

Returns:

  • (String, nil) —

    path of the codegraph executable, nil when not found



33
34
35
36
37
38
# File 'lib/bundler/codegraph/config.rb', line 33

def executable
  return @executable if @executable_resolved

  @executable_resolved = true
  @executable = which(binary)
end