Class: Diggit::Journal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJournal

Returns a new instance of Journal.



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

def initialize
  @sources = {}
  @workspace = WorkspaceEntry.new
end

Instance Attribute Details

#workspaceObject (readonly)

Returns the value of attribute workspace.



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

def workspace
  @workspace
end

Instance Method Details

#add_source(url) ⇒ Object



134
135
136
137
138
# File 'lib/dgit/core.rb', line 134

def add_source(url)
  key = url.split(/\|/)[0]
  @sources[key] = Source.new(url) unless @sources.key?(key)
  Dig.it.save_journal
end

#del_source(id) ⇒ Object



140
141
142
143
144
# File 'lib/dgit/core.rb', line 140

def del_source(id)
  source = sources_by_ids(id).first
  @sources.delete(source.url)
  Dig.it.save_journal
end

#source?(url) ⇒ Boolean

Returns:

  • (Boolean)


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

def source?(url)
  @sources.key?(url)
end

#sourcesObject



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

def sources
  @sources.values
end

#sources_by_ids(*ids) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/dgit/core.rb', line 119

def sources_by_ids(*ids)
  return sources if ids.empty?
  source_array = sources
  result = []
  ids.each do |id|
    raise "No such source index #{id}." if id >= source_array.length
    result << source_array[id]
  end
  result
end

#sources_by_state(state, error = false) ⇒ Object



115
116
117
# File 'lib/dgit/core.rb', line 115

def sources_by_state(state, error = false)
  @sources.select { |_u, s| s.entry.state == state && s.entry.error? == error }.values
end