Class: RubyLens::Index::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/index/manifest.rb

Defined Under Namespace

Classes: DependencySystem, GitPackagePaths, NixStoreProvider, Package

Constant Summary collapse

UnsafeGitRequirePath =
Class.new(StandardError)
UnsafeGitPackageFile =
Class.new(StandardError)
GIT_SKIP_REASONS =
DependencyWarning::REASONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, lockfile: nil) ⇒ Manifest

Returns a new instance of Manifest.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubylens/index/manifest.rb', line 40

def initialize(root:, lockfile: nil)
  @root = Pathname(root).expand_path.realpath
  @lockfile = Pathname(lockfile || @root.join("Gemfile.lock")).expand_path
  @nix_store_provider = NixStoreProvider.new
  @warnings = []
  @dependency_warnings = []
  @packages = []
  @dependency_systems = []
  @package_roots = []
  @package_index_by_file = {}
  @package_index_cache = {}
  @relative_workspace_path_cache = {}
  @git_spec_indexes = {}.compare_by_identity
end

Instance Attribute Details

#dependency_systemsObject (readonly)

Returns the value of attribute dependency_systems.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def dependency_systems
  @dependency_systems
end

#dependency_warningsObject (readonly)

Returns the value of attribute dependency_warnings.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def dependency_warnings
  @dependency_warnings
end

#filesObject (readonly)

Returns the value of attribute files.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def files
  @files
end

#packagesObject (readonly)

Returns the value of attribute packages.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def packages
  @packages
end

#rootObject (readonly)

Returns the value of attribute root.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def root
  @root
end

#warningsObject (readonly)

Returns the value of attribute warnings.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def warnings
  @warnings
end

#workspace_filesObject (readonly)

Returns the value of attribute workspace_files.



34
35
36
# File 'lib/rubylens/index/manifest.rb', line 34

def workspace_files
  @workspace_files
end

Class Method Details

.build(root:, lockfile: nil) ⇒ Object



36
37
38
# File 'lib/rubylens/index/manifest.rb', line 36

def self.build(root:, lockfile: nil)
  new(root: root, lockfile: lockfile).tap(&:build)
end

Instance Method Details

#buildObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubylens/index/manifest.rb', line 55

def build
  @workspace_files = GitRepository.new(@root).selected_files.freeze
  @workspace_file_set = @workspace_files.to_set
  build_packages
  @package_roots = @packages.each_with_index.map { |package, index| [package.root, index] }
    .sort_by do |package_root, index|
      package = @packages.fetch(index)
      [-package_root.to_s.length, package.name, package.version, index]
    end
  build_package_index
  @files = (@workspace_files + @packages.flat_map(&:files)).uniq.freeze
  @dependency_warnings.sort_by! { |warning| [warning.fetch("name"), warning.fetch("reason")] }
  @dependency_warnings.freeze
  self
end

#package_index_for(path) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/rubylens/index/manifest.rb', line 71

def package_index_for(path)
  path = path.to_s
  return @package_index_by_file[path] if @package_index_by_file.key?(path)
  return @package_index_cache[path] if @package_index_cache.key?(path)

  @package_index_cache[path] = uncached_package_index_for(path)
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
  nil
end

#relative_workspace_path(path) ⇒ Object



85
86
87
88
89
90
# File 'lib/rubylens/index/manifest.rb', line 85

def relative_workspace_path(path)
  path = path.to_s
  return @relative_workspace_path_cache[path] if @relative_workspace_path_cache.key?(path)

  @relative_workspace_path_cache[path] = uncached_relative_workspace_path(path)
end

#workspace_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rubylens/index/manifest.rb', line 81

def workspace_path?(path)
  Paths.inside?(path, @root)
end