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.



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

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.



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

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



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

def remote
  @remote
end

#repo_dirObject (readonly)

Returns the value of attribute repo_dir.



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

def repo_dir
  @repo_dir
end

Instance Method Details

#has?(config_entry) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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



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

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



63
64
65
66
67
68
69
70
71
# File 'lib/rbs/collection/sources/git.rb', line 63

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

#versions(config_entry) ⇒ Object



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

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