Class: Bundler::Codegraph::Config
- Inherits:
-
Object
- Object
- Bundler::Codegraph::Config
- 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
-
#binary ⇒ Object
readonly
Returns the value of attribute binary.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#exclude_patterns ⇒ Object
readonly
Returns the value of attribute exclude_patterns.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
-
#excluded?(gem_name) ⇒ Boolean
True when the gem matches one of the exclusion globs.
-
#executable ⇒ String?
Resolved lazily, once: the
PATHlookup only runs when something actually needs the binary. -
#initialize(env: ENV) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(env: ENV) ⇒ Config
Returns a new instance of Config.
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
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.
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.
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 |