Class: Diggit::Journal
- Inherits:
-
Object
- Object
- Diggit::Journal
- Defined in:
- lib/dgit/core.rb
Instance Attribute Summary collapse
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #add_source(url) ⇒ Object
- #del_source(id) ⇒ Object
-
#initialize ⇒ Journal
constructor
A new instance of Journal.
- #source?(url) ⇒ Boolean
- #sources ⇒ Object
- #sources_by_ids(*ids) ⇒ Object
- #sources_by_state(state, error = false) ⇒ Object
Constructor Details
#initialize ⇒ Journal
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
#workspace ⇒ Object (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
131 132 133 |
# File 'lib/dgit/core.rb', line 131 def source?(url) @sources.key?(url) end |
#sources ⇒ Object
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 |