Class: Raykit::Git::Repositories

Inherits:
Array
  • Object
show all
Defined in:
lib/raykit/git/repositories.rb

Overview

Functionality to manage a remote git repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Repositories

Returns a new instance of Repositories.



9
10
11
12
# File 'lib/raykit/git/repositories.rb', line 9

def initialize(filename)
    @filename=filename
    open(@filename)
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/raykit/git/repositories.rb', line 7

def filename
  @filename
end

Instance Method Details

#import(pattern) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/raykit/git/repositories.rb', line 34

def import(pattern)
    git_dirs = Array.new
    Dir.chdir(work_dir) do
        Dir.glob('**/.git'){|git_dir|
            dir = File.expand_path('..',git_dir)
            if(dir.length > 0)
                git_dirs.insert(0,dir)
            end
        }
    end

    git_dirs.each{|git_dir|
        dir=Raykit::Git::Directory.new(git_dir)
        remote=dir.remote
        if(remote.include?(pattern) && !include?(remote))
            insert(-1,remote)
        end
    }
    save(@filename)
    self
end

#open(filename) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/raykit/git/repositories.rb', line 14

def open(filename)
    if(File.exist?(filename))
        JSON.parse(File.read(filename)).each{|url|
            insert(-1,url)
        }
    else
        puts "filename #{filename} does not exist"
    end
end

#save(filename) ⇒ Object



24
25
26
27
28
# File 'lib/raykit/git/repositories.rb', line 24

def save(filename)
    File.open(@filename,'w'){|f|
        f.write(self.to_json)
    }
end

#work_dirObject



30
31
32
# File 'lib/raykit/git/repositories.rb', line 30

def work_dir
    Environment::get_dev_dir('work')
end