Module: GitProjectConfig::ClassMethods
- Defined in:
- lib/helpers/git_project_config.rb
Overview
Create YML config
Instance Method Summary collapse
-
#add_remotes_to_hash(g, dir) ⇒ Object
Create a hash for remotes.
-
#check_config ⇒ Object
Check for the config.
-
#create_config(dir, group = nil) ⇒ Object
Create a configuration file based on a root path.
-
#create_directory(path) ⇒ Object
Create dir unless it exists.
- #create_project_info_hash(projects, dir, group, config_file) ⇒ Object
-
#create_root_dir(path) ⇒ Object
Create root_dir.
- #create_root_path(path) ⇒ Object
-
#create_yaml_file(config_file, projects) ⇒ Object
Create YAML file.
-
#project_info_hash(dir, project, group) ⇒ Object
Create hash for the project.
Instance Method Details
#add_remotes_to_hash(g, dir) ⇒ Object
Create a hash for remotes
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/helpers/git_project_config.rb', line 43 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 ⇒ Object
Check for the config
25 26 27 28 29 30 31 32 33 |
# File 'lib/helpers/git_project_config.rb', line 25 def check_config if ENV['GIT_PROJECTS'] puts "Checking repositories. If things go wrong, update #{ENV['GIT_PROJECTS']}".green else fail "Please add the path your git projects config. \n export GIT_PROJECTS=/path/to/git_projects.yml" end end |
#create_config(dir, group = nil) ⇒ Object
Create a configuration file based on a root path
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/helpers/git_project_config.rb', line 74 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) ⇒ Object
Create dir unless it exists
14 15 16 17 |
# 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) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/helpers/git_project_config.rb', line 66 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) ⇒ Object
Create root_dir
20 21 22 |
# 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) ⇒ Object
9 10 11 |
# 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) ⇒ Object
Create YAML file
36 37 38 39 40 |
# File 'lib/helpers/git_project_config.rb', line 36 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) ⇒ Object
Create hash for the project
57 58 59 60 61 62 63 64 |
# File 'lib/helpers/git_project_config.rb', line 57 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 |