Class: Git::Duo::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/git/duo/repo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, opts = {}) ⇒ Repo

Returns a new instance of Repo.



13
14
15
16
# File 'lib/git/duo/repo.rb', line 13

def initialize(directory, opts = {})
  @directory = File.expand_path(directory)
  @wrapper = opts.fetch(:wrapper) { Git::Duo::Wrapper.new(git_directory) }
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



11
12
13
# File 'lib/git/duo/repo.rb', line 11

def directory
  @directory
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



11
12
13
# File 'lib/git/duo/repo.rb', line 11

def wrapper
  @wrapper
end

Class Method Details

.currentObject



7
8
9
# File 'lib/git/duo/repo.rb', line 7

def self.current
  new Dir.pwd
end

Instance Method Details

#authorsObject



18
19
20
21
22
23
# File 'lib/git/duo/repo.rb', line 18

def authors
  return @authors if defined? @authors
  config.
    reject {|key| non_git_author? key }.
    map {|a| Git::Duo::Author.import(a) }
end

#authors=(*new_authors) ⇒ Object



25
26
27
# File 'lib/git/duo/repo.rb', line 25

def authors= *new_authors
  @authors = *new_authors
end

#committerObject



29
30
31
32
33
34
# File 'lib/git/duo/repo.rb', line 29

def committer
  name = wrapper.config("user.name").shift
  email = wrapper.config("user.email").shift

  Author.new(name: name, email: email).to_s
end

#emailObject



36
37
38
39
40
41
42
# File 'lib/git/duo/repo.rb', line 36

def email
  return @email if defined? @email
  config.
    select {|key| non_git_author? key }.
    map {|key| key.gsub(/^email\s/, '') }.
    first
end

#email=(new_email) ⇒ Object



44
45
46
# File 'lib/git/duo/repo.rb', line 44

def email=(new_email)
  @email = new_email
end

#saveObject



52
53
54
55
# File 'lib/git/duo/repo.rb', line 52

def save
  save_email if email
  save_authors if authors
end

#solo!Object



48
49
50
# File 'lib/git/duo/repo.rb', line 48

def solo!
  wrapper.config '--remove-section user'
end