Class: Gitload::RepoChain

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gitload/repo_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, repos = [], options = {}) ⇒ RepoChain

Returns a new instance of RepoChain.



8
9
10
11
12
# File 'lib/gitload/repo_chain.rb', line 8

def initialize config, repos = [], options = {}
  @config = config
  @repos = repos
  @rename = options[:rename]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/gitload/repo_chain.rb', line 5

def config
  @config
end

#reposObject (readonly)

Returns the value of attribute repos.



6
7
8
# File 'lib/gitload/repo_chain.rb', line 6

def repos
  @repos
end

Instance Method Details

#<<(repo) ⇒ Object



14
15
16
17
# File 'lib/gitload/repo_chain.rb', line 14

def << repo
  @repos << repo
  self
end

#add(repos) ⇒ Object



19
20
21
22
23
24
# File 'lib/gitload/repo_chain.rb', line 19

def add repos
  # TODO: remove
  repos = repos.repos while repos.respond_to? :repos
  @repos += repos
  self
end

#by(*owners) ⇒ Object



26
27
28
29
# File 'lib/gitload/repo_chain.rb', line 26

def by *owners
  normalized_owners = owners.collect{ |owner| owner.to_s.downcase }
  select{ |repo| normalized_owners.include? repo.owner.to_s.downcase }
end

#cloneObject



73
74
75
# File 'lib/gitload/repo_chain.rb', line 73

def clone
  clone_into
end

#clone_into(dest = nil) ⇒ Object



81
82
83
# File 'lib/gitload/repo_chain.rb', line 81

def clone_into dest = nil
  clone_repos :into, dest
end

#clone_to(dest = nil) ⇒ Object



77
78
79
# File 'lib/gitload/repo_chain.rb', line 77

def clone_to dest = nil
  clone_repos :to, dest
end

#forksObject



51
52
53
# File 'lib/gitload/repo_chain.rb', line 51

def forks
  select &:fork?
end

#from(*sources) ⇒ Object



31
32
33
# File 'lib/gitload/repo_chain.rb', line 31

def from *sources
  select{ |repo| sources.include? repo.source }
end

#named(*criteria) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitload/repo_chain.rb', line 35

def named *criteria
  compiled_criteria = criteria.collect do |criterion|
    if criterion.kind_of? Regexp
      Proc.new{ |repo| repo.name.match criterion }
    else
      Proc.new{ |repo| repo.name.downcase == criterion.to_s.downcase }
    end
  end

  select do |repo|
    compiled_criteria.any? do |criterion|
      criterion.call repo
    end
  end
end

#prefix(prefix) ⇒ Object



68
69
70
71
# File 'lib/gitload/repo_chain.rb', line 68

def prefix prefix
  @prefix = prefix
  self
end

#reject(&block) ⇒ Object



59
60
61
# File 'lib/gitload/repo_chain.rb', line 59

def reject &block
  dup @repos.reject(&block)
end

#rename(pattern = nil, replacement = nil, &block) ⇒ Object



63
64
65
66
# File 'lib/gitload/repo_chain.rb', line 63

def rename pattern = nil, replacement = nil, &block
  @rename_block = block || Proc.new{ |name| name.sub pattern, replacement }
  self
end

#select(&block) ⇒ Object



55
56
57
# File 'lib/gitload/repo_chain.rb', line 55

def select &block
  dup @repos.select(&block)
end