Class: RBS::CLI::LibraryOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLibraryOptions

Returns a new instance of LibraryOptions.



21
22
23
24
25
26
27
28
# File 'lib/rbs/cli.rb', line 21

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

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

Instance Attribute Details

#config_pathObject

Returns the value of attribute config_path.



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

def config_path
  @config_path
end

#core_rootObject

Returns the value of attribute core_root.



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

def core_root
  @core_root
end

#dirsObject (readonly)

Returns the value of attribute dirs.



19
20
21
# File 'lib/rbs/cli.rb', line 19

def dirs
  @dirs
end

#libsObject (readonly)

Returns the value of attribute libs.



18
19
20
# File 'lib/rbs/cli.rb', line 18

def libs
  @libs
end

#reposObject (readonly)

Returns the value of attribute repos.



17
18
19
# File 'lib/rbs/cli.rb', line 17

def repos
  @repos
end

Instance Method Details

#loaderObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rbs/cli.rb', line 30

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)
  if config_path
    lock_path = Collection::Config.to_lockfile_path(config_path)
    if lock_path.file?
      lock = Collection::Config::Lockfile.from_lockfile(lockfile_path: lock_path, data: YAML.load_file(lock_path.to_s))
    end
  end
  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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rbs/cli.rb', line 58

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 configuration (default: #{@config_path})") do |path|
    self.config_path = Pathname(path).expand_path
  end

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

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

  opts
end