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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/raykit/git/repositories.rb', line 49

def import(pattern)
    if(is_remote_url(pattern))
        remote=pattern
        if(!include?(remote))
            insert(-1,remote)
        end
    else
        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
        }
    end
    save(@filename)
    self
end

#is_remote_url(pattern) ⇒ Object



36
37
38
39
40
# File 'lib/raykit/git/repositories.rb', line 36

def is_remote_url pattern
    return true if(pattern.include?('http://'))
    return true if(pattern.include?('https://'))
    false
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

#remove(url) ⇒ Object



42
43
44
45
46
47
# File 'lib/raykit/git/repositories.rb', line 42

def remove url
    if(include?(url))
        self.delete(url)
        save(@filename)
    end
end

#save(filename) ⇒ Object



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

def save(filename)
    File.open(@filename,'w'){|f|
        #json = JSON.pretty_generate(self)

        f.write(JSON.pretty_generate(self))
        #f.write(self.to_json)

    }
end

#work_dirObject



32
33
34
# File 'lib/raykit/git/repositories.rb', line 32

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