Class: Bundler::Codegraph::Indexer

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

Overview

Builds a CodeGraph index for a single gem directory.

Never raises: every failure mode is reported as a status symbol, because this runs from a Bundler hook where an exception would abort the whole bundle install.

Constant Summary collapse

INDEX_DIRNAME =
'.codegraph'
DATABASE_NAME =
'codegraph.db'
BACKUP_DIRNAME =
'.codegraph.bundler-codegraph-backup'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name:, config: Config.new, force: false, sync: false, skip_failed: false) ⇒ Indexer

rubocop:disable-next Metrics/ParameterLists

Parameters:

  • path (String) —

    absolute path of the directory to index

  • name (String) —

    gem name, used for the exclusion patterns

  • config (Config) (defaults to: Config.new)
  • force (Boolean) (defaults to: false) —

    drop and rebuild an existing index

  • sync (Boolean) (defaults to: false) —

    run codegraph sync on an existing index instead of skipping it, which also completes an index a killed run left behind

  • skip_failed (Boolean) (defaults to: false) —

    skip a directory codegraph already failed on, as long as its error log is there



30
31
32
33
34
35
36
37
38
# File 'lib/bundler/codegraph/indexer.rb', line 30

def initialize(path, name:, config: Config.new, force: false, sync: false, skip_failed: false)
  @path        = path.to_s
  @name        = name.to_s
  @config      = config
  @force       = force
  @sync        = sync
  @skip_failed = skip_failed
  @error_log   = nil
end

Instance Attribute Details

#config ⇒ Object (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def config
  @config
end

#force ⇒ Object (readonly)

Returns the value of attribute force.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def force
  @force
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def name
  @name
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def path
  @path
end

#skip_failed ⇒ Object (readonly)

Returns the value of attribute skip_failed.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def skip_failed
  @skip_failed
end

#sync ⇒ Object (readonly)

Returns the value of attribute sync.



19
20
21
# File 'lib/bundler/codegraph/indexer.rb', line 19

def sync
  @sync
end

Instance Method Details

#call ⇒ Symbol

Returns :indexed, :synced, :failed, :disabled, :excluded, :missing, :failed_before, :no_ruby, :already_indexed or :unavailable.

Returns:

  • (Symbol) —

    :indexed, :synced, :failed, :disabled, :excluded, :missing, :failed_before, :no_ruby, :already_indexed or :unavailable



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bundler/codegraph/indexer.rb', line 42

def call
  skipped = skip_reason
  return skipped if skipped

  Lock.synchronize do
    error_log.discard
    run
  end
rescue StandardError
  :failed
end

#indexed? ⇒ Boolean

Same criterion as codegraph itself: a .codegraph/ directory without its database is a leftover, not an index.

Returns:

  • (Boolean)


64
65
66
# File 'lib/bundler/codegraph/indexer.rb', line 64

def indexed?
  File.exist?(File.join(index_path, DATABASE_NAME))
end

#log_hint ⇒ String

Where to find codegraph's error output after call, as a suffix for a failure message (see ErrorLog#hint).

Returns:

  • (String)


58
59
60
# File 'lib/bundler/codegraph/indexer.rb', line 58

def log_hint
  @error_log ? @error_log.hint : ''
end