Class: RBS::Collection::Sources::Git

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name:, revision:, remote:, repo_dir:) ⇒ Git

Returns a new instance of Git.



15
16
17
18
19
20
21
# File 'lib/rbs/collection/sources/git.rb', line 15

def initialize(name:, revision:, remote:, repo_dir:)
  @name = name
  @remote = remote
  @repo_dir = repo_dir || 'gems'

  setup!(revision: revision)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/rbs/collection/sources/git.rb', line 13

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



13
14
15
# File 'lib/rbs/collection/sources/git.rb', line 13

def remote
  @remote
end

#repo_dirObject (readonly)

Returns the value of attribute repo_dir.



13
14
15
# File 'lib/rbs/collection/sources/git.rb', line 13

def repo_dir
  @repo_dir
end

Instance Method Details

#has?(config_entry) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/rbs/collection/sources/git.rb', line 23

def has?(config_entry)
  gem_name = config_entry['name']
  gem_repo_dir.join(gem_name).directory?
end

#install(dest:, config_entry:, stdout:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rbs/collection/sources/git.rb', line 33

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

#to_lockfileObject



78
79
80
81
82
83
84
85
86
# File 'lib/rbs/collection/sources/git.rb', line 78

def to_lockfile
  {
    'type' => 'git',
    'name' => name,
    'revision' => resolved_revision,
    'remote' => remote,
    'repo_dir' => repo_dir,
  }
end

#versions(config_entry) ⇒ Object



28
29
30
31
# File 'lib/rbs/collection/sources/git.rb', line 28

def versions(config_entry)
  gem_name = config_entry['name']
  gem_repo_dir.join(gem_name).glob('*/').map { |path| path.basename.to_s }
end