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.rb, lib/rbs/collection/config/lockfile_generator.rb |
Overview
This class represent the configuration file.
Constant Summary
-
PATH =
# File 'lib/rbs/collection/config.rb', line 17Pathname('rbs_collection.yaml')
Class Method Summary
- .find_config_path
- .from_path(path)
-
.generate_lockfile(config_path:, definition:, with_lockfile: true)
Generate a rbs lockfile from
Gemfile.lock
to #config_path. - .new(data, config_path:) ⇒ Config constructor
- .to_lockfile_path(config_path)
Instance Attribute Summary
- #config_path readonly
- #data readonly
Instance Method Summary
Constructor Details
.new(data, config_path:) ⇒ Config
# File 'lib/rbs/collection/config.rb', line 49
def initialize(data, config_path:) @data = data @config_path = config_path end
Class Method Details
.find_config_path
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 21
def self.find_config_path current = Pathname.pwd loop do config_path = current.join(PATH) return config_path if config_path.exist? current = current.join('..') return nil if current.root? end end
.from_path(path)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 41
def self.from_path(path) new(YAML.load(path.read), config_path: path) end
.generate_lockfile(config_path:, definition:, 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 34
def self.generate_lockfile(config_path:, definition:, with_lockfile: true) config = from_path(config_path) lockfile = LockfileGenerator.generate(config: config, definition: definition, with_lockfile: with_lockfile) [config, lockfile] end
.to_lockfile_path(config_path)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 45
def self.to_lockfile_path(config_path) config_path.sub_ext('.lock' + config_path.extname) end
Instance Attribute Details
#config_path (readonly)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 19
attr_reader :config_path, :data
#data (readonly)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 19
attr_reader :config_path, :data
Instance Method Details
#gem(gem_name)
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 54
def gem(gem_name) gems.find { |gem| gem['name'] == gem_name } end
#gems
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 74
def gems @data['gems'] ||= [] end
#repo_path
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 58
def repo_path @config_path.dirname.join repo_path_data end
#repo_path_data
[ GitHub ]# File 'lib/rbs/collection/config.rb', line 62
def repo_path_data Pathname(@data["path"]) end