Class: Diggit::Source

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Source

Returns a new instance of Source.



62
63
64
65
66
# File 'lib/dgit/core.rb', line 62

def initialize(url)
  @url = url
  @entry = Journal.new_source_entry
  @repository = nil
end

Instance Attribute Details

#entryObject

Returns the value of attribute entry.



60
61
62
# File 'lib/dgit/core.rb', line 60

def entry
  @entry
end

#repositoryObject (readonly)

Returns the value of attribute repository.



59
60
61
# File 'lib/dgit/core.rb', line 59

def repository
  @repository
end

#urlObject (readonly)

Returns the value of attribute url.



59
60
61
# File 'lib/dgit/core.rb', line 59

def url
  @url
end

Instance Method Details

#all_analysesObject



104
105
106
# File 'lib/dgit/core.rb', line 104

def all_analyses
  performed_analyses + ongoing_analyses
end

#cloneObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/dgit/core.rb', line 116

def clone
  if File.exist?(folder)
    Rugged::Repository.new(folder)
  else
    Rugged::Repository.clone_at(url, folder)
  end
  self.state = :cloned
rescue => e
  Log.error "Error cloning #{url}."
  self.error = Journal.dump_error(e)
end

#cloned?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/dgit/core.rb', line 100

def cloned?
  @entry[:state] == :cloned
end

#errorObject



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

def error
  @entry[:last_error]
end

#error=(error) ⇒ Object



84
85
86
# File 'lib/dgit/core.rb', line 84

def error=(error)
  @entry[:last_error] = error
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !(@entry[:last_error].nil? || @entry[:last_error].empty?)
end

#folderObject



72
73
74
# File 'lib/dgit/core.rb', line 72

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

#idObject



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

def id
  @url.id
end

#load_repositoryObject



128
129
130
131
# File 'lib/dgit/core.rb', line 128

def load_repository
  fail "Source not cloned #{url}." if new?
  @repository = Rugged::Repository.new(folder)
end

#new?Boolean

Returns:

  • (Boolean)


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

def new?
  @entry[:state] == :new
end

#ongoing_analysesObject



112
113
114
# File 'lib/dgit/core.rb', line 112

def ongoing_analyses
  @entry[:ongoing_analyses]
end

#performed_analysesObject



108
109
110
# File 'lib/dgit/core.rb', line 108

def performed_analyses
  @entry[:performed_analyses]
end

#stateObject



88
89
90
# File 'lib/dgit/core.rb', line 88

def state
  @entry[:state]
end

#state=(state) ⇒ Object



92
93
94
# File 'lib/dgit/core.rb', line 92

def state=(state)
  @entry[:state] = state
end