Class: MultiRepo::Repo
- Inherits:
-
Object
- Object
- MultiRepo::Repo
- Defined in:
- lib/multi_repo/repo.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #chdir ⇒ Object
- #detect_readme_file ⇒ Object
- #git ⇒ Object
-
#initialize(name, config: nil, dry_run: false) ⇒ Repo
constructor
A new instance of Repo.
- #rm_file(file) ⇒ Object
- #short_name ⇒ Object
- #write_file(file, content, **kwargs) ⇒ Object
Constructor Details
#initialize(name, config: nil, dry_run: false) ⇒ Repo
Returns a new instance of Repo.
8 9 10 11 12 13 |
# File 'lib/multi_repo/repo.rb', line 8 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 |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/multi_repo/repo.rb', line 5 def config @config end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
6 7 8 |
# File 'lib/multi_repo/repo.rb', line 6 def dry_run @dry_run end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/multi_repo/repo.rb', line 5 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/multi_repo/repo.rb', line 5 def path @path end |
Instance Method Details
#chdir ⇒ Object
21 22 23 24 |
# File 'lib/multi_repo/repo.rb', line 21 def chdir git # Ensures the clone exists Dir.chdir(path) { yield } end |
#detect_readme_file ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/multi_repo/repo.rb', line 48 def detect_readme_file chdir do %w[README.md README README.txt].detect do |f| File.exist?(f) end end end |
#git ⇒ Object
17 18 19 |
# File 'lib/multi_repo/repo.rb', line 17 def git @git ||= MultiRepo::Service::Git.new(path: path, clone_source: config.clone_source || "[email protected]:#{name}.git", dry_run: dry_run) end |
#rm_file(file) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/multi_repo/repo.rb', line 38 def rm_file(file) return unless path.join(file).exist? if dry_run puts "** dry-run: Removing #{path.join(file).}".light_black else chdir { FileUtils.rm_f(file) } end end |
#short_name ⇒ Object
26 27 28 |
# File 'lib/multi_repo/repo.rb', line 26 def short_name name.split("/").last end |
#write_file(file, content, **kwargs) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/multi_repo/repo.rb', line 30 def write_file(file, content, **kwargs) if dry_run puts "** dry-run: Writing #{path.join(file).}".light_black else chdir { File.write(file, content) } end end |