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.



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

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

Instance Attribute Details

#workspaceObject (readonly)

Returns the value of attribute workspace.



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

def workspace
  @workspace
end

Instance Method Details

#add_source(url) ⇒ Object



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

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



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

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

#source?(url) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#sourcesObject



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

def sources
	@sources.values
end

#sources_by_ids(*ids) ⇒ Object



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

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



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

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