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



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

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.



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

def entry
  @entry
end

#oidObject (readonly)

Returns the value of attribute oid.



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

def oid
  @oid
end

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#cloneObject



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

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



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

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

#idObject



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

def id
  @url.id
end

#load_repositoryObject



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

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