123456789_123456789_123456789_123456789_123456789_

Class: RBS::CLI::LibraryOptions

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/cli.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newLibraryOptions

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 16

def initialize()
  @core_root = EnvironmentLoader::DEFAULT_CORE_ROOT
  @repos = []

  @libs = []
  @dirs = []
  @config_path = Collection::Config::PATH
end

Instance Attribute Details

#config_path (rw)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 11

attr_accessor :config_path

#core_root (rw)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 10

attr_accessor :core_root

#dirs (readonly)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 14

attr_reader :dirs

#libs (readonly)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 13

attr_reader :libs

#repos (readonly)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 12

attr_reader :repos

Instance Method Details

#loader

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 25

def loader
  repository = Repository.new(no_stdlib: core_root.nil?)
  repos.each do |repo|
    repository.add(Pathname(repo))
  end

  loader = EnvironmentLoader.new(core_root: core_root, repository: repository)
  lock = config_path&.then { |p| Collection::Config.lockfile_of(p) }
  loader.add_collection(lock) if lock

  dirs.each do |dir|
    loader.add(path: Pathname(dir))
  end

  libs.each do |lib|
    name, version = lib.split(/:/, 2)
    next unless name
    loader.add(library: name, version: version)
  end

  loader
end

#setup_library_options(opts)

[ GitHub ]

  
# File 'lib/rbs/cli.rb', line 48

def setup_library_options(opts)
  opts.on("-r LIBRARY", "Load RBS files of the library") do |lib|
    libs << lib
  end

  opts.on("-I DIR", "Load RBS files from the directory") do |dir|
    dirs << dir
  end

  opts.on("--no-stdlib", "Skip loading standard library signatures") do
    self.core_root = nil
  end

  opts.on('--collection PATH', "File path of collection configration (default: #{Collection::Config::PATH})") do |path|
    self.config_path = Pathname(path).expand_path
  end

  opts.on('--no-collection', 'Ignore collection configration') do
    self.config_path = nil
  end

  opts.on("--repo DIR", "Add RBS repository") do |dir|
    repos << dir
  end

  opts
end