Class: Rbs::Src::Gem
- Inherits:
-
Object
- Object
- Rbs::Src::Gem
- Defined in:
- lib/rbs/src/gem.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rbs_prefix ⇒ Object
readonly
Returns the value of attribute rbs_prefix.
-
#repository_dir ⇒ Object
readonly
Returns the value of attribute repository_dir.
-
#repository_prefix ⇒ Object
readonly
Returns the value of attribute repository_prefix.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #checkout(runner, repository_url:, commit:) ⇒ Object
- #clone(runner, repository_url:, commit:) ⇒ Object
-
#initialize(name:, version:, repository_prefix:, repository_dir:, rbs_prefix:) ⇒ Gem
constructor
A new instance of Gem.
- #link ⇒ Object
- #rbs_path(suffix = version) ⇒ Object
- #repository_path ⇒ Object
- #repository_root ⇒ Object
- #status(runner, commit:) ⇒ Object
Constructor Details
#initialize(name:, version:, repository_prefix:, repository_dir:, rbs_prefix:) ⇒ Gem
Returns a new instance of Gem.
6 7 8 9 10 11 12 |
# File 'lib/rbs/src/gem.rb', line 6 def initialize(name:, version:, repository_prefix:, repository_dir:, rbs_prefix:) @name = name @version = version @repository_prefix = repository_prefix @repository_dir = repository_dir @rbs_prefix = rbs_prefix end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/rbs/src/gem.rb', line 4 def name @name end |
#rbs_prefix ⇒ Object (readonly)
Returns the value of attribute rbs_prefix.
4 5 6 |
# File 'lib/rbs/src/gem.rb', line 4 def rbs_prefix @rbs_prefix end |
#repository_dir ⇒ Object (readonly)
Returns the value of attribute repository_dir.
4 5 6 |
# File 'lib/rbs/src/gem.rb', line 4 def repository_dir @repository_dir end |
#repository_prefix ⇒ Object (readonly)
Returns the value of attribute repository_prefix.
4 5 6 |
# File 'lib/rbs/src/gem.rb', line 4 def repository_prefix @repository_prefix end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/rbs/src/gem.rb', line 4 def version @version end |
Instance Method Details
#checkout(runner, repository_url:, commit:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbs/src/gem.rb', line 38 def checkout(runner, repository_url:, commit:) unless runner.query!("git", "status", "-s", "-z", chdir: repository_root).split("\0").empty? runner.puts "📣 Stashing uncommited changes... Restore the changes by: `git stash pop`" runner.execute!("git", "stash", "-u", "-m", "Stash by rbs-src on #{name}-#{version}", chdir: repository_root) end return if runner.query!("git", "rev-parse", "HEAD", chdir: repository_root).chomp == commit unless runner.query?("git", "cat-file", "-e", commit, chdir: repository_root) runner.puts "💾 Fetching from #{repository_url}..." runner.execute!("git", "remote", "set-url", "origin", repository_url, chdir: repository_root) runner.execute!("git", "fetch", "origin", chdir: repository_root) end runner.puts "💪 Checking out the commit #{commit}..." runner.execute!("git", "checkout", commit, chdir: repository_root) end |
#clone(runner, repository_url:, commit:) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbs/src/gem.rb', line 56 def clone(runner, repository_url:, commit:) runner.puts "git clone..." runner.execute!("git", "clone", "--filter=blob:none", "--sparse", repository_url, repository_root.to_s) dirs = runner.query!("git", "ls-tree", "-d", "--name-only", "-z", "HEAD", chdir: repository_root).split("\0") dirs.delete(repository_dir.to_s) runner.execute!("git", "sparse-checkout", "set", *dirs, repository_dir.join(name).to_s, chdir: repository_root) if commit runner.puts "git checkout..." runner.execute!("git", "checkout", commit, chdir: repository_root) end end |
#link ⇒ Object
68 69 70 71 72 73 |
# File 'lib/rbs/src/gem.rb', line 68 def link Pathname.glob(rbs_path("*").to_s).each do |path| File.unlink(path.to_s) end File.symlink(repository_path.relative_path_from(rbs_path.parent), rbs_path) end |
#rbs_path(suffix = version) ⇒ Object
22 23 24 |
# File 'lib/rbs/src/gem.rb', line 22 def rbs_path(suffix = version) rbs_prefix + "#{name}-#{suffix}" end |
#repository_path ⇒ Object
18 19 20 |
# File 'lib/rbs/src/gem.rb', line 18 def repository_path repository_root.join(repository_dir, name, version) end |
#repository_root ⇒ Object
14 15 16 |
# File 'lib/rbs/src/gem.rb', line 14 def repository_root repository_prefix + "#{name}-#{version}" end |
#status(runner, commit:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbs/src/gem.rb', line 26 def status(runner, commit:) unless runner.query!("git", "status", "-s", "-z", chdir: repository_root).split("\0").empty? return :dirty end if runner.query!("git", "rev-parse", "HEAD", chdir: repository_root).chomp != commit return :commit_mismatch end :ok end |