Class: Repository

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/clenver/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(uri, config = nil) ⇒ Repository

TODO: think about better way to handle dst from URI



8
9
10
11
12
13
14
# File 'lib/clenver/repository.rb', line 8

def initialize(uri, config = nil)
  @repo_uri = uri
  @dst = get_dst(config)
  @remotes = get_remotes(config)
  @abs_path = nil
  @repo = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/clenver/repository.rb', line 6

def config
  @config
end

#dstObject

Returns the value of attribute dst.



6
7
8
# File 'lib/clenver/repository.rb', line 6

def dst
  @dst
end

#remotesObject

Returns the value of attribute remotes.



6
7
8
# File 'lib/clenver/repository.rb', line 6

def remotes
  @remotes
end

#repoObject

Returns the value of attribute repo.



6
7
8
# File 'lib/clenver/repository.rb', line 6

def repo
  @repo
end

#repo_uriObject

Returns the value of attribute repo_uri.



6
7
8
# File 'lib/clenver/repository.rb', line 6

def repo_uri
  @repo_uri
end

Instance Method Details

#add_remotesObject



43
44
45
46
47
48
49
50
# File 'lib/clenver/repository.rb', line 43

def add_remotes
  logger.debug("self.inspect:#{self.inspect}")
  unless remotes.nil?
    for name, uri in remotes do
      Git.open(dst).add_remote(name, uri)
    end
  end
end

#cloneObject



34
35
36
37
# File 'lib/clenver/repository.rb', line 34

def clone
  repo = Git.clone(repo_uri, dst)
  logger.debug("clone:#{repo}")
end

#get_abs_pathObject



39
40
41
# File 'lib/clenver/repository.rb', line 39

def get_abs_path
  @abs_path
end

#get_dst(config) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/clenver/repository.rb', line 24

def get_dst(config)
  unless config.nil?
    if config.has_key?('dst')
      return config['dst'][0]
    end
  end
  logger.debug("dst:#{Dir::pwd + "/" + File.basename(repo_uri, '.git')}")
  Dir::pwd + "/" + File.basename(repo_uri, '.git')
end

#get_remotes(config) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/clenver/repository.rb', line 16

def get_remotes(config)
  unless config.nil?
    if config.has_key?('remotes')
      config['remotes']
    end
  end
end