lib/raykit/git/repositories.rb
require_relative('./directory.rb') module Raykit module Git # Functionality to manage a remote git repository class Repositories < Array attr_accessor :filename def initialize(filename) @filename=filename open(@filename) end 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 def save(filename) File.open(@filename,'w'){|f| f.write(self.to_json) } end def import(pattern) git_dirs = Array.new Dir.chdir(Environment::get_dev_dir('work')) 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 end end end