Class: Diggit::Source
- Inherits:
-
Object
- Object
- Diggit::Source
- Defined in:
- lib/dgit/core.rb
Constant Summary collapse
- DEFAULT_BRANCH =
"origin/master".freeze
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #clone ⇒ Object
- #folder ⇒ Object
- #id ⇒ Object
-
#initialize(url) ⇒ Source
constructor
A new instance of Source.
- #load_repository ⇒ Object
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
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
67 68 69 |
# File 'lib/dgit/core.rb', line 67 def entry @entry end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
67 68 69 |
# File 'lib/dgit/core.rb', line 67 def oid @oid end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
67 68 69 |
# File 'lib/dgit/core.rb', line 67 def repository @repository end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
67 68 69 |
# File 'lib/dgit/core.rb', line 67 def url @url end |
Instance Method Details
#clone ⇒ Object
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 |
#folder ⇒ Object
81 82 83 |
# File 'lib/dgit/core.rb', line 81 def folder Dig.it.file_path("sources/#{id}") end |
#id ⇒ Object
77 78 79 |
# File 'lib/dgit/core.rb', line 77 def id @url.id end |
#load_repository ⇒ Object
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 |