module GitProjectConfig::ClassMethods
Create YML config
Public Instance Methods
add_remotes_to_hash(g, dir)
click to toggle source
Create a hash for remotes
# File lib/helpers/git_project_config.rb, line 41 def add_remotes_to_hash(g, dir) remotes_h = {} r = {} remotes_h.tap do |remotes| g.remotes.each do |remote| r[remote.name] = remote.url end r['all'] = true r['root_dir'] = dir remotes.merge!(r) end end
check_config()
click to toggle source
Check for the config
# File lib/helpers/git_project_config.rb, line 25 def check_config puts "Checking repositories. If things go wrong, update #{ENV['GIT_PROJECTS']}".green fail "Please add the path your git projects config. \n export GIT_PROJECTS=/path/to/git_projects.yml" unless ENV['GIT_PROJECTS'] end
create_config(dir, group = nil)
click to toggle source
Create a configuration file based on a root path
# File lib/helpers/git_project_config.rb, line 72 def create_config(dir, group = nil) dir = dir.respond_to?(:first) ? dir.first : dir config_file = File.join(dir, 'git-projects.yml') group ||= dir.split(File::SEPARATOR).last if dir fail "The config file, #{config_file} exists" if File.exist?(config_file) projects = [] create_project_info_hash(projects, dir, group, config_file) puts "You can later fetch changes through: \ngit-projects fetch #{group}".green end
create_directory(path)
click to toggle source
Create dir unless it exists
# File lib/helpers/git_project_config.rb, line 14 def create_directory(path) `mkdir -p #{path}` unless File.directory?(path) puts 'Creating directory: '.green + "#{path}".blue end
create_project_info_hash(projects, dir, group, config_file)
click to toggle source
# File lib/helpers/git_project_config.rb, line 64 def create_project_info_hash(projects, dir, group, config_file) Dir.entries(dir)[2..-1].each do |project| projects << project_info_hash(dir, project, group) create_yaml_file(config_file, projects) end end
create_root_dir(path)
click to toggle source
Create root_dir
# File lib/helpers/git_project_config.rb, line 20 def create_root_dir(path) GitProject.create_directory(path) unless File.directory?(path) end
create_root_path(path)
click to toggle source
# File lib/helpers/git_project_config.rb, line 9 def create_root_path(path) @project.create_root_path(path) end
create_yaml_file(config_file, projects)
click to toggle source
Create YAML file
# File lib/helpers/git_project_config.rb, line 34 def create_yaml_file(config_file, projects) File.open(config_file, 'w') do |f| f.write projects.to_yaml.gsub(/- /, '').gsub(/ /, ' ').gsub(/---/, '') end end
project_info_hash(dir, project, group)
click to toggle source
Create hash for the project
# File lib/helpers/git_project_config.rb, line 55 def project_info_hash(dir, project, group) g = Git.open(File.join(dir, project)) p = {} p.tap do |pr| pr[project] = add_remotes_to_hash(g, dir) pr[project]['group'] = group end end