Class: RBS::Collection::Config
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Exceptions:
| |
Inherits: | Object |
Defined in: | lib/rbs/collection/config.rb, lib/rbs/collection/config/lockfile_generator.rb |
Overview
This class represent the configration file.
Constant Summary
-
PATH =
# File 'lib/rbs/collection/config.rb', line 17Pathname('rbs_collection.yaml')
Class Method Summary
- .from_path(path)
-
.generate_lockfile(config_path:, gemfile_lock_path:, with_lockfile: true)
Generate a rbs lockfile from
Gemfile.lock
toconfig_path
. - .lockfile_of(config_path)
- .new(data, config_path:) ⇒ Config constructor
- .to_lockfile_path(config_path)
Instance Method Summary
- #add_gem(gem)
-
#check_rbs_availability!
It raises an error when there are non-available libraries.
- #dump_to(io)
- #gem(gem_name)
- #gems
- #repo_path
- #sources
Constructor Details
.new(data, config_path:) ⇒ Config
# File 'lib/rbs/collection/config.rb', line 38
def initialize(data, config_path:) @data = data @config_path = config_path end
Class Method Details
.from_path(path)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 25
def self.from_path(path) new(YAML.load(path.read), config_path: path) end
.generate_lockfile(config_path:, gemfile_lock_path:, with_lockfile: true)
Generate a rbs lockfile from Gemfile.lock
to config_path
. If with_lockfile
is true, it respects existing rbs lockfile.
# File 'lib/rbs/collection/config.rb', line 21
def self.generate_lockfile(config_path:, gemfile_lock_path:, with_lockfile: true) LockfileGenerator.generate(config_path: config_path, gemfile_lock_path: gemfile_lock_path, with_lockfile: with_lockfile) end
.lockfile_of(config_path)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 29
def self.lockfile_of(config_path) lock_path = to_lockfile_path(config_path) from_path lock_path if lock_path.exist? end
.to_lockfile_path(config_path)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 34
def self.to_lockfile_path(config_path) config_path.sub_ext('.lock' + config_path.extname) end
Instance Method Details
#add_gem(gem)
[ GitHub ]#check_rbs_availability!
It raises an error when there are non-available libraries
# File 'lib/rbs/collection/config.rb', line 73
def check_rbs_availability! raise CollectionNotAvailable unless repo_path.exist? gems.each do |gem| case gem['source']['type'] when 'git' = repo_path.join(gem['name'], gem['version'], Sources::Git::METADATA_FILENAME) raise CollectionNotAvailable unless .exist? raise CollectionNotAvailable unless gem == YAML.load( .read) end end end
#dump_to(io)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 64
def dump_to(io) YAML.dump(@data, io) end
#gem(gem_name)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 47
def gem(gem_name) gems.find { |gem| gem['name'] == gem_name } end
#gems
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 68
def gems @data['gems'] ||= [] end
#repo_path
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 51
def repo_path @config_path.dirname.join @data['path'] end