Class: Moku::ArchiveReference

Inherits:
Object
  • Object
show all
Defined in:
lib/moku/archive_reference.rb

Overview

A version-control archive at a specific point in time.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, commitish, runner = Moku.git_runner) ⇒ ArchiveReference

Create a new instance without resolving the commitish.

Parameters:

  • url (String)
  • commitish (String)

32
33
34
35
36
# File 'lib/moku/archive_reference.rb', line 32

def initialize(url, commitish, runner = Moku.git_runner)
  @url = url
  @commitish = commitish
  @runner = runner
end

Instance Attribute Details

#commitishObject (readonly)

Returns the value of attribute commitish


38
39
40
# File 'lib/moku/archive_reference.rb', line 38

def commitish
  @commitish
end

#urlObject (readonly)

Returns the value of attribute url


38
39
40
# File 'lib/moku/archive_reference.rb', line 38

def url
  @url
end

Class Method Details

.at(url, commitish, runner = Moku.git_runner) ⇒ ArchiveReference

Create a new instance, and interface with the backend to resolve the commitish.

Parameters:

  • url (String)
  • commitish (String)

Returns:


22
23
24
25
26
27
# File 'lib/moku/archive_reference.rb', line 22

def self.at(url, commitish, runner = Moku.git_runner)
  sha = runner.sha(url, "#{commitish}^{}")
  sha ||= runner.sha(url, commitish)
  sha ||= commitish
  new(url, sha, runner)
end

.from_hash(hash, runner = Moku.git_runner) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/moku/archive_reference.rb', line 9

def self.from_hash(hash, runner = Moku.git_runner)
  new(
    hash["url"],
    hash["commitish"],
    runner
  )
end

Instance Method Details

#at(new_commitish) ⇒ ArchiveReference

Get a resolved reference to the commitish. When given nil, this will defer to #latest

Parameters:

  • commitish (String)

Returns:


53
54
55
56
57
# File 'lib/moku/archive_reference.rb', line 53

def at(new_commitish)
  return latest unless new_commitish

  self.class.at(url, new_commitish, runner)
end

#branch(new_branch) ⇒ Object

Get a reference to the branch without resolving it. No checks are performed against the paramater

Parameters:

  • new_branch (String)

    the branch name


62
63
64
# File 'lib/moku/archive_reference.rb', line 62

def branch(new_branch)
  self.class.new(url, new_branch, runner)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/moku/archive_reference.rb', line 66

def eql?(other)
  url == other.url && commitish == other.commitish
end

#latestArchiveReference

Get a reference to the latest commit for the commitish. The definition of the “latest commit” is reflexive for any commitish that is not a branch–i.e., the latest commit of a specific tag or SHA is the corresponding SHA itself.

Returns:


45
46
47
# File 'lib/moku/archive_reference.rb', line 45

def latest
  self.class.at(url, commitish, runner)
end

#to_hashObject


70
71
72
73
74
75
# File 'lib/moku/archive_reference.rb', line 70

def to_hash
  {
    "url"       => url,
    "commitish" => commitish
  }
end