Class: Diggit::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/dgit/core.rb

Constant Summary collapse

DEFAULT_BRANCH =
"origin/master".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Source

Returns a new instance of Source.



70
71
72
73
74
75
76
# File 'lib/dgit/core.rb', line 70

def initialize(url)
	infos = url.split(/\|/)
	@url = infos[0]
	@oid = infos.size > 1 ? infos[1] : DEFAULT_BRANCH
	@entry = SourceEntry.new
	@repository = nil
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



68
69
70
# File 'lib/dgit/core.rb', line 68

def entry
  @entry
end

#oidObject (readonly)

Returns the value of attribute oid.



68
69
70
# File 'lib/dgit/core.rb', line 68

def oid
  @oid
end

#repositoryObject (readonly)

Returns the value of attribute repository.



68
69
70
# File 'lib/dgit/core.rb', line 68

def repository
  @repository
end

#urlObject (readonly)

Returns the value of attribute url.



68
69
70
# File 'lib/dgit/core.rb', line 68

def url
  @url
end

Instance Method Details

#cloneObject



86
87
88
89
90
91
92
93
94
95
# File 'lib/dgit/core.rb', line 86

def clone
	@entry.error = nil
	@repository = File.exist?(folder) ? Rugged::Repository.new(folder) : Rugged::Repository.clone_at(url, folder)
	@repository.checkout(@oid, { strategy: :force })
	@entry.state = :cloned
rescue StandardError => e
	Log.error "Error cloning #{url}: #{e}"
	e.backtrace.each { |l| Log.debug(l) }
	@entry.error = e
end

#folderObject



82
83
84
# File 'lib/dgit/core.rb', line 82

def folder
	Dig.it.file_path("sources/#{id}")
end

#idObject



78
79
80
# File 'lib/dgit/core.rb', line 78

def id
	@url.id
end

#load_repositoryObject



97
98
99
100
101
# File 'lib/dgit/core.rb', line 97

def load_repository
	raise "Source not cloned #{url}." if @entry.new?
	@repository = Rugged::Repository.new(folder)
	@repository.checkout(@oid, { strategy: :force })
end