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
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
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
68 69 70 |
# File 'lib/dgit/core.rb', line 68 def entry @entry end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
68 69 70 |
# File 'lib/dgit/core.rb', line 68 def oid @oid end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
68 69 70 |
# File 'lib/dgit/core.rb', line 68 def repository @repository end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
68 69 70 |
# File 'lib/dgit/core.rb', line 68 def url @url end |
Instance Method Details
#clone ⇒ Object
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 |
#folder ⇒ Object
82 83 84 |
# File 'lib/dgit/core.rb', line 82 def folder Dig.it.file_path("sources/#{id}") end |
#id ⇒ Object
78 79 80 |
# File 'lib/dgit/core.rb', line 78 def id @url.id end |
#load_repository ⇒ Object
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 |