Class: Ed::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/ed/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Ed::Repository

Returns a instance of Ed::Repository.

Parameters:

  • path (String, #to_s)

    The URI to a git repository.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ed/repository.rb', line 59

def initialize path
  @path = copy!(path.to_s)

  parent = Process.pid

  at_exit do
    if parent == Process.pid
      FileUtils.rm_rf(@path)
    end
  end
end

Instance Attribute Details

#pathString (readonly)

Returns The path to the repository on local disk.

Returns:

  • (String)

    The path to the repository on local disk.



50
51
52
# File 'lib/ed/repository.rb', line 50

def path
  @path
end

Class Method Details

.is_local?(path) ⇒ Boolean

Returns true if the repository is considered to exist on filesystem.

Parameters:

  • path (String)

    The URI to a git a repository.

Returns:

  • (Boolean)

    Returns true if the repository is considered to exist on filesystem.



40
41
42
# File 'lib/ed/repository.rb', line 40

def is_local? path
  path[0..6] == "file://" || !path.include?(":")
end

.ls_remote(*args) {|sha, ref| ... } ⇒ Enumerator

Returns a Enumerator if no block is given.

Parameters:

  • *args (String)

    The same commands given to ‘git ls-remote’.

Yield Parameters:

  • sha (String)

    The commit SHA.

  • ref (String)

    The reference (e.g: HEAD, tag, or branch)

Returns:

  • (Enumerator)

    Returns a Enumerator if no block is given.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ed/repository.rb', line 20

def ls_remote *args
  unless block_given?
    return enum_for(:ls_remote, *args)
  end

  output = `git ls-remote #{args.join(' ')}`

  output.each_line do |line|
    sha, ref = line.split(/\s+/, 2)
    yield sha, ref.chomp
  end
end

Instance Method Details

#checkout(*args) ⇒ void

This method returns an undefined value.

Parameters:

  • *options (String)

    The same commands given to ‘git checkout’



77
78
79
# File 'lib/ed/repository.rb', line 77

def checkout *args
  git "checkout", *args
end