Class: Gloo::Objs::EachRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/objs/ctrl/each_repo.rb

Constant Summary collapse

FILE =
'file'.freeze
REPO =
'repo'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, iterator_obj) ⇒ EachRepo


Create Iterator



19
20
21
22
# File 'lib/gloo/objs/ctrl/each_repo.rb', line 19

def initialize( engine, iterator_obj )
  @engine = engine
  @iterator_obj = iterator_obj
end

Class Method Details

.use_for?(iterator_obj) ⇒ Boolean

Use this iterator for each loop?

Returns:



32
33
34
35
36
# File 'lib/gloo/objs/ctrl/each_repo.rb', line 32

def self.use_for?( iterator_obj )
  return true if iterator_obj.find_child REPO

  return false
end

Instance Method Details

#find_all_git_projects(path) ⇒ Object

Find all git projects in a path.



46
47
48
49
50
51
52
53
54
# File 'lib/gloo/objs/ctrl/each_repo.rb', line 46

def find_all_git_projects( path )
  path.children.collect do |f|
    if f.directory? && ( File.basename( f ) == '.git' )
      File.dirname( f )
    elsif f.directory?
      find_all_git_projects( f )
    end
  end.flatten.compact
end

#runObject

Run for repo.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gloo/objs/ctrl/each_repo.rb', line 59

def run
  path = @iterator_obj.in_value
  return unless path

  path = Pathname.new( path )
  repos = find_all_git_projects( path )
  repos.each do |o|
    set_repo o
    @iterator_obj.run_do
  end
end

#set_repo(path) ⇒ Object

Set the value of the repo. This is a path to the repo.



75
76
77
78
79
80
# File 'lib/gloo/objs/ctrl/each_repo.rb', line 75

def set_repo( path )
  o = @iterator_obj.find_child REPO
  return unless o

  o.set_value path
end