Class: RBS::Collection::Sources::Git
- Inherits:
-
Object
- Object
- RBS::Collection::Sources::Git
- Includes:
- Base
- Defined in:
- lib/rbs/collection/sources/git.rb
Defined Under Namespace
Classes: CommandError
Constant Summary collapse
- METADATA_FILENAME =
'.rbs_meta.yaml'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#repo_dir ⇒ Object
readonly
Returns the value of attribute repo_dir.
Instance Method Summary collapse
- #has?(config_entry) ⇒ Boolean
-
#initialize(name:, revision:, remote:, repo_dir:) ⇒ Git
constructor
A new instance of Git.
- #install(dest:, config_entry:, stdout:) ⇒ Object
- #manifest_of(config_entry) ⇒ Object
- #to_lockfile ⇒ Object
- #versions(config_entry) ⇒ Object
Methods included from Base
Constructor Details
#initialize(name:, revision:, remote:, repo_dir:) ⇒ Git
Returns a new instance of Git.
18 19 20 21 22 23 24 |
# File 'lib/rbs/collection/sources/git.rb', line 18 def initialize(name:, revision:, remote:, repo_dir:) @name = name @remote = remote @repo_dir = repo_dir || 'gems' setup!(revision: revision) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/rbs/collection/sources/git.rb', line 16 def name @name end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
16 17 18 |
# File 'lib/rbs/collection/sources/git.rb', line 16 def remote @remote end |
#repo_dir ⇒ Object (readonly)
Returns the value of attribute repo_dir.
16 17 18 |
# File 'lib/rbs/collection/sources/git.rb', line 16 def repo_dir @repo_dir end |
Instance Method Details
#has?(config_entry) ⇒ Boolean
26 27 28 29 |
# File 'lib/rbs/collection/sources/git.rb', line 26 def has?(config_entry) gem_name = config_entry['name'] gem_repo_dir.join(gem_name).directory? end |
#install(dest:, config_entry:, stdout:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbs/collection/sources/git.rb', line 36 def install(dest:, config_entry:, stdout:) gem_name = config_entry['name'] version = config_entry['version'] or raise gem_dir = dest.join(gem_name, version) if gem_dir.directory? if (prev = YAML.load_file(gem_dir.join(METADATA_FILENAME))) == config_entry stdout.puts "Using #{format_config_entry(config_entry)}" else # @type var prev: RBS::Collection::Config::gem_entry stdout.puts "Updating to #{format_config_entry(config_entry)} from #{format_config_entry(prev)}" FileUtils.remove_entry_secure(gem_dir.to_s) _install(dest: dest, config_entry: config_entry) end else stdout.puts "Installing #{format_config_entry(config_entry)}" _install(dest: dest, config_entry: config_entry) end end |
#manifest_of(config_entry) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rbs/collection/sources/git.rb', line 56 def manifest_of(config_entry) gem_name = config_entry['name'] version = config_entry['version'] or raise gem_dir = gem_repo_dir.join(gem_name, version) manifest_path = gem_dir.join('manifest.yaml') YAML.safe_load(manifest_path.read) if manifest_path.exist? end |
#to_lockfile ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/rbs/collection/sources/git.rb', line 90 def to_lockfile { 'type' => 'git', 'name' => name, 'revision' => resolved_revision, 'remote' => remote, 'repo_dir' => repo_dir, } end |
#versions(config_entry) ⇒ Object
31 32 33 34 |
# File 'lib/rbs/collection/sources/git.rb', line 31 def versions(config_entry) gem_name = config_entry['name'] gem_repo_dir.join(gem_name).glob('*/').map { |path| path.basename.to_s } end |