clindex 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/index.rb +60 -56
- metadata +21 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f19c672983f0cb3dca28cc030abb2b67629f254f0c1f7ff9d28eed1d4e5a6658
|
4
|
+
data.tar.gz: 600dc6c4592d6ba37123f2e4f6335100c6fff84b4389cc090678567ffe5f9e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff793d34f4cc2e549319c224bd92dee260742a9e99190212a4a557bb95429eadc1225b571490da4e8eb7f9543b18c9fc0f2ce935cb588088ffdf7cfd58f99dc5
|
7
|
+
data.tar.gz: 5e2e63bfbc5ccc279b7e7b06b429b51857f953d19eaab327e5c799a8a52354270ecca671e337191764327bb77e63e24049eb901795853fb37cf70caaeba7b99c
|
data/src/index.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'drb'
|
2
4
|
require 'rubygems'
|
3
5
|
gem 'clutil'
|
@@ -12,10 +14,10 @@ class ClIndex
|
|
12
14
|
WAIT = true
|
13
15
|
NO_WAIT = false
|
14
16
|
|
15
|
-
def initialize(
|
17
|
+
def initialize(verbose_server = false)
|
16
18
|
@index = {}
|
17
|
-
@
|
18
|
-
@
|
19
|
+
@lock_mgr = ClIndexLockMgr.new
|
20
|
+
@verbose_server = verbose_server
|
19
21
|
end
|
20
22
|
|
21
23
|
def assign(src)
|
@@ -25,16 +27,16 @@ class ClIndex
|
|
25
27
|
# refactor with do_read?
|
26
28
|
def do_edit(wait)
|
27
29
|
locked = lock(ClIndexLockMgr::EDIT, wait)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
return unless locked
|
31
|
+
|
32
|
+
begin
|
33
|
+
yield if block_given?
|
34
|
+
ensure
|
35
|
+
unlock(ClIndexLockMgr::EDIT)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
def add(term, reference, wait=NO_WAIT)
|
39
|
+
def add(term, reference, wait = NO_WAIT)
|
38
40
|
success = false
|
39
41
|
do_edit(wait) {
|
40
42
|
@index[term] = [] if @index[term].nil?
|
@@ -45,11 +47,11 @@ class ClIndex
|
|
45
47
|
success
|
46
48
|
end
|
47
49
|
|
48
|
-
def remove(reference, wait=NO_WAIT)
|
50
|
+
def remove(reference, wait = NO_WAIT)
|
49
51
|
success = false
|
50
52
|
do_edit(wait) {
|
51
|
-
@index.each_pair do |term,
|
52
|
-
@index[term].delete(reference) if
|
53
|
+
@index.each_pair do |term, ref_array|
|
54
|
+
@index[term].delete(reference) if ref_array.include?(reference)
|
53
55
|
@index.delete(term) if @index[term].empty?
|
54
56
|
end
|
55
57
|
success = true
|
@@ -61,11 +63,11 @@ class ClIndex
|
|
61
63
|
# wait (defaults to false). If wait is false and a blocking action
|
62
64
|
# is preventing saving, the call returns immediately. If wait is true,
|
63
65
|
# save waits for the blocking action to complete before continuing.
|
64
|
-
def save(filename='index.dat', wait=NO_WAIT)
|
66
|
+
def save(filename = 'index.dat', wait = NO_WAIT)
|
65
67
|
locked = lock(ClIndexLockMgr::SAVE, wait)
|
66
68
|
if locked
|
67
69
|
begin
|
68
|
-
File.open(filename, File::CREAT|File::TRUNC|File::RDWR) do |f|
|
70
|
+
File.open(filename, File::CREAT | File::TRUNC | File::RDWR) do |f|
|
69
71
|
Marshal.dump(@index, f)
|
70
72
|
end
|
71
73
|
ensure
|
@@ -75,7 +77,7 @@ class ClIndex
|
|
75
77
|
locked
|
76
78
|
end
|
77
79
|
|
78
|
-
def load(filename='index.dat', wait=NO_WAIT)
|
80
|
+
def load(filename = 'index.dat', wait = NO_WAIT)
|
79
81
|
locked = lock(ClIndexLockMgr::LOAD, wait)
|
80
82
|
if locked
|
81
83
|
begin
|
@@ -89,14 +91,14 @@ class ClIndex
|
|
89
91
|
locked
|
90
92
|
end
|
91
93
|
|
92
|
-
def search(term, hits, wait=NO_WAIT)
|
93
|
-
puts 'searching...' if @
|
94
|
+
def search(term, hits, wait = NO_WAIT)
|
95
|
+
puts 'searching...' if @verbose_server
|
94
96
|
success = false
|
95
97
|
do_read(wait) {
|
96
98
|
success = true
|
97
99
|
terms = @index.keys.grep(/#{term}/i)
|
98
|
-
terms.each do |
|
99
|
-
hits << @index[
|
100
|
+
terms.each do |this_term|
|
101
|
+
hits << @index[this_term]
|
100
102
|
end
|
101
103
|
hits = hits.flatten.uniq.sort
|
102
104
|
}
|
@@ -105,30 +107,30 @@ class ClIndex
|
|
105
107
|
|
106
108
|
def do_read(wait)
|
107
109
|
locked = lock(ClIndexLockMgr::READ, wait)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
return unless locked
|
111
|
+
|
112
|
+
begin
|
113
|
+
yield if block_given?
|
114
|
+
ensure
|
115
|
+
unlock(ClIndexLockMgr::READ)
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
|
-
def all_terms(reference, wait=NO_WAIT)
|
119
|
+
def all_terms(reference, wait = NO_WAIT)
|
118
120
|
all = []
|
119
121
|
do_read(wait) {
|
120
|
-
@index.each do |term,
|
121
|
-
all << term if
|
122
|
+
@index.each do |term, ref_array|
|
123
|
+
all << term if ref_array.include?(reference)
|
122
124
|
end
|
123
125
|
}
|
124
126
|
all
|
125
127
|
end
|
126
128
|
|
127
|
-
def reference_exists?(reference, wait=NO_WAIT)
|
129
|
+
def reference_exists?(reference, wait = NO_WAIT)
|
128
130
|
exists = false
|
129
131
|
do_read(wait) {
|
130
|
-
@index.each do |
|
131
|
-
if
|
132
|
+
@index.each do |_, ref_array|
|
133
|
+
if ref_array.include? reference
|
132
134
|
exists = true
|
133
135
|
break
|
134
136
|
end
|
@@ -137,36 +139,36 @@ class ClIndex
|
|
137
139
|
exists
|
138
140
|
end
|
139
141
|
|
140
|
-
def term_exists?(term, wait=NO_WAIT)
|
142
|
+
def term_exists?(term, wait = NO_WAIT)
|
141
143
|
exists = false
|
142
144
|
do_read(wait) {
|
143
|
-
exists = @index.
|
145
|
+
exists = @index.key?(term)
|
144
146
|
}
|
145
147
|
exists
|
146
148
|
end
|
147
149
|
|
148
|
-
def lock(
|
149
|
-
@
|
150
|
+
def lock(lock_type, wait = NO_WAIT)
|
151
|
+
@lock_mgr.lock(lock_type, wait)
|
150
152
|
end
|
151
153
|
|
152
|
-
def unlock(
|
153
|
-
@
|
154
|
+
def unlock(lock_type)
|
155
|
+
@lock_mgr.unlock(lock_type)
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
157
159
|
class ThreadSafeArray
|
158
160
|
def initialize
|
159
161
|
@mutex = Mutex.new
|
160
|
-
@
|
162
|
+
@internal_array = []
|
161
163
|
end
|
162
164
|
|
163
165
|
def to_ary
|
164
|
-
@
|
166
|
+
@internal_array
|
165
167
|
end
|
166
168
|
|
167
169
|
def method_missing(method, *args, &block)
|
168
170
|
@mutex.synchronize do
|
169
|
-
@
|
171
|
+
@internal_array.send(method, *args, &block)
|
170
172
|
end
|
171
173
|
end
|
172
174
|
end
|
@@ -190,42 +192,44 @@ class ClIndexLockMgr
|
|
190
192
|
@mutex = Mutex.new
|
191
193
|
end
|
192
194
|
|
193
|
-
def lock_approved(
|
195
|
+
def lock_approved(lock_type)
|
194
196
|
result = true
|
195
197
|
@allowable.each_pair do |locked, allowable|
|
196
|
-
if @current.include?(locked) && !allowable.include?(
|
198
|
+
if @current.include?(locked) && !allowable.include?(lock_type)
|
197
199
|
result = false
|
198
200
|
end
|
199
|
-
break
|
201
|
+
break unless result
|
200
202
|
end
|
201
203
|
result
|
202
204
|
end
|
203
205
|
|
204
|
-
def lock(
|
206
|
+
def lock(lock_type, wait = false)
|
207
|
+
approved = nil
|
205
208
|
if wait
|
206
|
-
|
207
|
-
approved = lock_approved(
|
208
|
-
|
209
|
+
loop do
|
210
|
+
approved = lock_approved(lock_type)
|
211
|
+
break if approved
|
212
|
+
end
|
209
213
|
else
|
210
|
-
approved = lock_approved(
|
214
|
+
approved = lock_approved(lock_type)
|
211
215
|
end
|
212
|
-
@current <<
|
216
|
+
@current << lock_type if approved
|
213
217
|
approved
|
214
218
|
end
|
215
219
|
|
216
|
-
def unlock(
|
217
|
-
@current.delete(
|
220
|
+
def unlock(lock_type)
|
221
|
+
@current.delete(lock_type)
|
218
222
|
end
|
219
223
|
end
|
220
224
|
|
221
|
-
def launch_server(port='9110')
|
222
|
-
|
225
|
+
def launch_server(port = '9110')
|
226
|
+
idx_server = ClIndex.new(true)
|
223
227
|
puts "ClIndex launching on localhost:#{port}..."
|
224
|
-
DRb.start_service("druby://localhost:#{port}",
|
228
|
+
DRb.start_service("druby://localhost:#{port}", idx_server)
|
225
229
|
DRb.thread.join
|
226
230
|
end
|
227
231
|
|
228
|
-
if
|
232
|
+
if $0 == __FILE__
|
229
233
|
if if_switch('-s')
|
230
234
|
port = get_switch('-p')
|
231
235
|
if port
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clutil
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: A generic index DRb server. The core index is a hash, each key is an
|
42
56
|
individual term, each value is an array of references for that term. Searches the
|
43
57
|
index with a simple regexp grep against the hash keys to return a single array of
|
@@ -53,13 +67,13 @@ files:
|
|
53
67
|
homepage: https://github.com/chrismo/clindex
|
54
68
|
licenses: []
|
55
69
|
metadata: {}
|
56
|
-
post_install_message:
|
70
|
+
post_install_message:
|
57
71
|
rdoc_options: []
|
58
72
|
require_paths:
|
59
73
|
- src
|
60
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
75
|
requirements:
|
62
|
-
- - "
|
76
|
+
- - ">="
|
63
77
|
- !ruby/object:Gem::Version
|
64
78
|
version: '2.4'
|
65
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -68,9 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
70
84
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
85
|
+
rubygems_version: 3.3.26
|
86
|
+
signing_key:
|
74
87
|
specification_version: 4
|
75
88
|
summary: cLabs Index
|
76
89
|
test_files: []
|