Sha256: f31900ce1dd5e5c131227c6596242a6315644a6885b25024e45a2ed328a7461d
Contents?: true
Size: 1.23 KB
Versions: 9
Compression:
Stored size: 1.23 KB
Contents
require 'ostruct' module MultiRepo class Repo attr_reader :name, :config, :path attr_accessor :dry_run def initialize(name, config: nil, dry_run: false) @name = name @dry_run = dry_run @config = OpenStruct.new(config || {}) @path = MultiRepo.repos_dir.join(name) end alias to_s inspect def git @git ||= MultiRepo::Service::Git.new(path: path, clone_source: config.clone_source || "git@github.com:#{name}.git", dry_run: dry_run) end def chdir git # Ensures the clone exists Dir.chdir(path) { yield } end def short_name name.split("/").last end def write_file(file, content, **kwargs) if dry_run puts "** dry-run: Writing #{path.join(file).expand_path}".light_black else chdir { File.write(file, content) } end end def rm_file(file) return unless path.join(file).exist? if dry_run puts "** dry-run: Removing #{path.join(file).expand_path}".light_black else chdir { FileUtils.rm_f(file) } end end def detect_readme_file chdir do %w[README.md README README.txt].detect do |f| File.exist?(f) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems