Class: Tapioca::Gemfile

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/gemfile.rb

Defined Under Namespace

Classes: Gem

Constant Summary collapse

Spec =
T.type_alias do
  T.any(
    T.all(
      ::Bundler::StubSpecification,
      ::Bundler::RemoteSpecification
    ),
    ::Gem::Specification
  )
end

Instance Method Summary collapse

Constructor Details

#initializeGemfile

Returns a new instance of Gemfile.



21
22
23
24
25
26
# File 'lib/tapioca/gemfile.rb', line 21

def initialize
  @gemfile = T.let(File.new(Bundler.default_gemfile), File)
  @lockfile = T.let(File.new(Bundler.default_lockfile), File)
  @dependencies = T.let(nil, T.nilable(T::Array[Gem]))
  @definition = T.let(nil, T.nilable(Bundler::Definition))
end

Instance Method Details

#dependenciesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tapioca/gemfile.rb', line 29

def dependencies
  @dependencies ||= begin
    specs = definition.locked_gems.specs.to_a

    definition
      .resolve
      .materialize(specs)
      .map { |spec| Gem.new(spec) }
      .reject { |gem| gem.ignore?(dir) }
      .uniq(&:rbi_file_name)
      .sort_by(&:rbi_file_name)
  end
end

#gem(gem_name) ⇒ Object



44
45
46
# File 'lib/tapioca/gemfile.rb', line 44

def gem(gem_name)
  dependencies.detect { |dep| dep.name == gem_name }
end

#requireObject



49
50
51
# File 'lib/tapioca/gemfile.rb', line 49

def require
  T.unsafe(runtime).setup(*groups).require(*groups)
end