Class: Gel::Catalog::CompactIndex
- Inherits:
-
Object
- Object
- Gel::Catalog::CompactIndex
- Includes:
- Common
- Defined in:
- lib/gel/catalog/compact_index.rb
Constant Summary collapse
- CACHE_TYPE =
"index"
Instance Method Summary collapse
-
#initialize ⇒ CompactIndex
constructor
A new instance of CompactIndex.
- #prepare(gems) ⇒ Object
- #refresh_gem(gem_name, immediate = true) ⇒ Object
- #update ⇒ Object
Methods included from Common
Constructor Details
#initialize ⇒ CompactIndex
Returns a new instance of CompactIndex.
13 14 15 16 17 18 19 20 21 |
# File 'lib/gel/catalog/compact_index.rb', line 13 def initialize(*) super @gem_tokens = Hash.new("NONE") @needs_update = true @updating = false @active_gems = Set.new @pending_gems = Set.new end |
Instance Method Details
#prepare(gems) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/gel/catalog/compact_index.rb', line 23 def prepare(gems) @monitor.synchronize do @pending_gems.merge(gems) end update @monitor.synchronize do @refresh_cond.wait_until { gems.all? { |g| _info(g) } } end end |
#refresh_gem(gem_name, immediate = true) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gel/catalog/compact_index.rb', line 76 def refresh_gem(gem_name, immediate = true) update already_active = nil @monitor.synchronize do if @updating && !@gem_tokens.key?(gem_name) @pending_gems << gem_name return end already_active = !@active_gems.add?(gem_name) end unless @gem_tokens.key?(gem_name) @monitor.synchronize do @gem_info[gem_name] = {} @refresh_cond.broadcast return end end error = lambda do |ex| @monitor.synchronize do @gem_info[gem_name] = ex @refresh_cond.broadcast end end pinboard.async_file(uri("info", gem_name), token: @gem_tokens[gem_name], only_updated: already_active, error: error) do |f| dependency_names = Set.new info = {} started = false f.each_line do |line| unless started started ||= line == "---\n" next end line.chop! version, rest = line.split(" ", 2) deps, attrs = rest.split("|", 2) deps = deps.split(",").map do |entry| key, constraints = entry.split(":", 2) constraints = constraints.split("&") [key, constraints] end attributes = { dependencies: deps } attrs.scan(/(\w+):((?:[^,]+|,(?!\w+:))*)/) do |key, value| attributes[key.to_sym] = value end deps.each do |name, _| dependency_names << name end info[version] = attributes end @monitor.synchronize do @gem_info[gem_name] = info @refresh_cond.broadcast end end end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gel/catalog/compact_index.rb', line 33 def update @monitor.synchronize do return false unless @needs_update @needs_update = false @updating = true end error = lambda do |ex| @monitor.synchronize do @error = ex @refresh_cond.broadcast end end pinboard.async_file(uri("versions"), tail: true, error: error) do |f| new_tokens = {} started = false f.each_line do |line| unless started started ||= line == "---\n" next end line.chop! name, _versions, token = line.split new_tokens[name] = token end @monitor.synchronize do @gem_tokens.update new_tokens @updating = false @refresh_cond.broadcast end (@active_gems | @pending_gems).each do |name| refresh_gem(name) end end true end |