Class: Raykit::Git::Repositories
- Inherits:
-
Array
- Object
- Array
- Raykit::Git::Repositories
- Defined in:
- lib/raykit/git/repositories.rb
Overview
Functionality to manage a remote git repository
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #import(pattern) ⇒ Object
-
#initialize(filename) ⇒ Repositories
constructor
A new instance of Repositories.
- #is_remote_url(pattern) ⇒ Object
- #matches(pattern) ⇒ Object
- #open(filename) ⇒ Object
- #remove(url) ⇒ Object
- #save(_filename) ⇒ Object
- #work_dir ⇒ Object
Constructor Details
#initialize(filename) ⇒ Repositories
Returns a new instance of Repositories.
11 12 13 14 |
# File 'lib/raykit/git/repositories.rb', line 11 def initialize(filename) @filename = filename open(@filename) end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
9 10 11 |
# File 'lib/raykit/git/repositories.rb', line 9 def filename @filename end |
Instance Method Details
#import(pattern) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/raykit/git/repositories.rb', line 52 def import(pattern) imported = [] if is_remote_url(pattern) remote = pattern unless include?(remote) insert(-1, remote) imported.insert(-1, remote) end else git_dirs = [] Dir.chdir(work_dir) do Dir.glob("**/.git") do |git_dir| dir = File.("..", git_dir) git_dirs.insert(0, dir) if dir.length.positive? end end git_dirs.each do |git_dir| dir = Raykit::Git::Directory.new(git_dir) remote = dir.remote if remote.include?(pattern) && !include?(remote) insert(-1, remote) imported.insert(-1, remote) end end end save(@filename) imported end |
#is_remote_url(pattern) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/raykit/git/repositories.rb', line 38 def is_remote_url(pattern) return true if pattern.include?("http://") return true if pattern.include?("https://") false end |
#matches(pattern) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/raykit/git/repositories.rb', line 82 def matches(pattern) matches = [] REPOSITORIES.each do |url| matches << url if url.include?(pattern) end matches end |
#open(filename) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/raykit/git/repositories.rb', line 16 def open(filename) if File.exist?(filename) JSON.parse(File.read(filename)).each do |url| insert(-1, url) end else # puts "filename #{filename} does not exist" end end |
#remove(url) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/raykit/git/repositories.rb', line 45 def remove(url) if include?(url) delete(url) save(@filename) end end |
#save(_filename) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/raykit/git/repositories.rb', line 26 def save(_filename) File.open(@filename, "w") do |f| # json = JSON.pretty_generate(self) f.write(JSON.pretty_generate(self)) # f.write(self.to_json) end end |
#work_dir ⇒ Object
34 35 36 |
# File 'lib/raykit/git/repositories.rb', line 34 def work_dir Environment.get_dev_dir("work") end |