relaton 1.7.pre7 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +34 -0
  3. data/.github/workflows/ubuntu.yml +32 -0
  4. data/.github/workflows/windows.yml +35 -0
  5. data/docs/README.adoc +3 -233
  6. data/lib/relaton/config.rb +2 -3
  7. data/lib/relaton/db.rb +35 -247
  8. data/lib/relaton/db_cache.rb +6 -28
  9. data/lib/relaton/processor.rb +0 -11
  10. data/lib/relaton/registry.rb +1 -1
  11. data/lib/relaton/version.rb +1 -1
  12. data/lib/relaton.rb +7 -8
  13. data/relaton.gemspec +6 -8
  14. data/spec/relaton/db_cache_spec.rb +1 -1
  15. data/spec/relaton/db_spec.rb +0 -145
  16. data/spec/relaton/processor_spec.rb +0 -4
  17. data/spec/relaton/regirtry_spec.rb +44 -54
  18. data/spec/relaton_spec.rb +19 -120
  19. data/spec/vcr_cassetes/19133_2005.yml +20 -20
  20. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +10 -10
  21. data/spec/vcr_cassetes/fisp_140.yml +6 -6
  22. data/spec/vcr_cassetes/gb_t_20223_2006.yml +11 -15
  23. data/spec/vcr_cassetes/ieee_528_2019.yml +17 -17
  24. data/spec/vcr_cassetes/iho_b_11.yml +15 -15
  25. data/spec/vcr_cassetes/iso_111111119115_1.yml +5 -5
  26. data/spec/vcr_cassetes/iso_19115.yml +22 -22
  27. data/spec/vcr_cassetes/iso_19115_1.yml +20 -20
  28. data/spec/vcr_cassetes/iso_19115_1_2.yml +39 -39
  29. data/spec/vcr_cassetes/iso_awi_24229.yml +22 -22
  30. data/spec/vcr_cassetes/ogc_19_025r1.yml +1902 -2554
  31. data/spec/vcr_cassetes/ogm_ami4ccm_1_0.yml +7 -7
  32. data/spec/vcr_cassetes/rfc_8341.yml +15 -47
  33. data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
  34. data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +30 -30
  35. data/spec/vcr_cassetes/w3c_json_ld11.yml +12 -12
  36. metadata +51 -61
  37. data/.github/workflows/rake.yml +0 -46
  38. data/globalcache/iec/iec_60050_102_2007.xml +0 -58
  39. data/globalcache/iec/version +0 -1
  40. data/lib/relaton/workers_pool.rb +0 -23
  41. data/spec/vcr_cassetes/cie_001_1980.yml +0 -120
  42. data/spec/vcr_cassetes/ecma_6.yml +0 -159
  43. data/spec/vcr_cassetes/hist_cmbined_included.yml +0 -105
  44. data/spec/vcr_cassetes/iec_60050_102_2007.yml +0 -285
  45. data/spec/vcr_cassetes/iec_combined_included.yml +0 -945
  46. data/spec/vcr_cassetes/iso_combined_applied.yml +0 -361
  47. data/spec/vcr_cassetes/iso_combined_included.yml +0 -361
  48. data/spec/vcr_cassetes/itu_combined_included.yml +0 -1296
  49. data/spec/vcr_cassetes/rfc_unsuccess.yml +0 -70
data/lib/relaton/db.rb CHANGED
@@ -10,121 +10,39 @@ module Relaton
10
10
  # @param local_cache [String] directory of local DB
11
11
  def initialize(global_cache, local_cache)
12
12
  @registry = Relaton::Registry.instance
13
- gpath = global_cache && File.expand_path(global_cache)
14
- @db = open_cache_biblio(gpath, type: :global)
15
- lpath = local_cache && File.expand_path(local_cache)
16
- @local_db = open_cache_biblio(lpath, type: :local)
17
- @static_db = open_cache_biblio File.expand_path("../relaton/static_cache", __dir__)
18
- @queues = {}
13
+ @db = open_cache_biblio(global_cache, type: :global)
14
+ @local_db = open_cache_biblio(local_cache, type: :local)
15
+ @db_name = global_cache
16
+ @local_db_name = local_cache
17
+ static_db_name = File.expand_path "../relaton/static_cache", __dir__
18
+ @static_db = open_cache_biblio static_db_name
19
19
  end
20
20
 
21
- # Move global or local caches to anothe dirs
22
- # @param new_dir [String, nil]
23
- # @param type: [Symbol]
24
- # @return [String, nil]
25
- def mv(new_dir, type: :global)
26
- case type
27
- when :global
28
- @db&.mv new_dir
29
- when :local
30
- @local_db&.mv new_dir
31
- end
32
- end
33
-
34
- # Clear global and local databases
35
- def clear
36
- @db&.clear
37
- @local_db&.clear
38
- end
39
-
40
- ##
41
21
  # The class of reference requested is determined by the prefix of the code:
42
22
  # GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for iecbib,
43
- #
44
23
  # @param code [String] the ISO standard Code to look up (e.g. "ISO 9000")
45
24
  # @param year [String] the year the standard was published (optional)
46
- #
47
- # @param opts [Hash] options
48
- # @option opts [Boolean] :all_parts If all-parts reference is required
49
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
50
- # @option opts [Integer] :retries (1) Number of network retries
51
- #
52
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
25
+ # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
26
+ # @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
53
27
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
54
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
55
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
56
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
57
- # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
58
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
59
- # RelatonW3c::W3cBibliographicItem
60
- ##
28
+ # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
61
29
  def fetch(code, year = nil, opts = {})
62
30
  stdclass = standard_class(code) || return
63
- processor = @registry.processors[stdclass]
64
- ref = processor.respond_to?(:urn_to_code) ? processor.urn_to_code(code)&.first : code
65
- ref ||= code
66
- result = combine_doc ref, year, opts, stdclass
67
- result ||= check_bibliocache(ref, year, opts, stdclass)
68
- result
69
- end
70
-
71
- # @see Relaton::Db#fetch
72
- def fetch_db(code, year = nil, opts = {})
73
- opts[:fetch_db] = true
74
- fetch code, year, opts
75
- end
76
-
77
- # fetch all standards from DB
78
- # @param test [String, nil]
79
- # @param edition [String], nil
80
- # @param year [Integer, nil]
81
- # @return [Array]
82
- def fetch_all(text = nil, edition: nil, year: nil)
83
- result = @static_db.all { |file, yml| search_yml file, yml, text, edition, year }.compact
84
- db = @db || @local_db
85
- result += db.all { |file, xml| search_xml file, xml, text, edition, year }.compact if db
86
- result
87
- end
88
-
89
- # Fetch asynchronously
90
- def fetch_async(code, year = nil, opts = {}, &_block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
91
- stdclass = standard_class code
92
- if stdclass
93
- unless @queues[stdclass]
94
- processor = @registry.processors[stdclass]
95
- wp = WorkersPool.new(processor.threads) { |args| yield fetch *args }
96
- @queues[stdclass] = { queue: Queue.new, workers_pool: wp }
97
- Thread.new { process_queue @queues[stdclass] }
98
- end
99
- @queues[stdclass][:queue] << [code, year, opts]
100
- else yield nil
101
- end
31
+ check_bibliocache(code, year, opts, stdclass)
102
32
  end
103
33
 
104
34
  # @param code [String]
105
35
  # @param year [String, NilClass]
106
36
  # @param stdclass [Symbol, NilClass]
107
- #
108
37
  # @param opts [Hash]
109
- # @option opts [Boolean] :all_parts If all-parts reference is required
110
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
111
- # @option opts [Integer] :retries (1) Number of network retries
112
- #
113
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
114
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
115
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
116
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
117
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
118
- # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
119
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
120
- # RelatonW3c::W3cBibliographicItem
121
38
  def fetch_std(code, year = nil, stdclass = nil, opts = {})
122
39
  std = nil
123
40
  @registry.processors.each do |name, processor|
124
41
  std = name if processor.prefix == stdclass
125
42
  end
126
- std = standard_class(code) or return nil unless std
127
-
43
+ unless std
44
+ std = standard_class(code) or return nil
45
+ end
128
46
  check_bibliocache(code, year, opts, std)
129
47
  end
130
48
 
@@ -168,115 +86,27 @@ module Relaton
168
86
 
169
87
  private
170
88
 
171
- # @param file [String] file path
172
- # @param yml [String] content in YAML format
173
- # @param text [String, nil] text to serach
174
- # @param edition [String, nil] edition to filter
175
- # @param year [Integer, nil] year to filter
176
- # @return [BibliographicItem, nil]
177
- def search_yml(file, yml, text, edition, year)
178
- item = search_edition_year(file, yml, edition, year)
179
- return unless item
180
-
181
- item if match_xml_text(item.to_xml(bibdata: true), text)
182
- end
183
-
184
- # @param file [String] file path
185
- # @param xml [String] content in XML format
186
- # @param text [String, nil] text to serach
187
- # @param edition [String, nil] edition to filter
188
- # @param year [Integer, nil] year to filter
189
- # @return [BibliographicItem, nil]
190
- def search_xml(file, xml, text, edition, year)
191
- return unless text.nil? || match_xml_text(xml, text)
192
-
193
- search_edition_year(file, xml, edition, year)
194
- end
195
-
196
- # @param file [String] file path
197
- # @param content [String] content in XML or YAmL format
198
- # @param edition [String, nil] edition to filter
199
- # @param year [Integer, nil] year to filter
200
- # @return [BibliographicItem, nil]
201
- def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
202
- processor = @registry.processors[standard_class(file.split("/")[-2])]
203
- item = file.match?(/xml$/) ? processor.from_xml(content) : processor.hash_to_bib(YAML.safe_load(content))
204
- item if (edition.nil? || item.edition == edition) &&
205
- (year.nil? || item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s })
206
- end
207
-
208
- # @param xml [String] content in XML format
209
- # @param text [String, nil] text to serach
210
- # @return [Boolean]
211
- def match_xml_text(xml, text)
212
- %r{((?<attr>=((?<apstr>')|"))|>).*?#{text}.*?(?(<attr>)(?(<apstr>)'|")|<)}mi.match?(xml)
213
- end
214
-
215
- # @param code [String]
216
- # @param year [String, nil]
217
- # @param stdslass [String]
218
- #
219
- # @param opts [Hash] options
220
- # @option opts [Boolean] :all_parts If all-parts reference is required
221
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
222
- # @option opts [Integer] :retries (1) Number of network retries
223
- #
224
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
225
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
226
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
227
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
228
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
229
- # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
230
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
231
- # RelatonW3c::W3cBibliographicItem
232
- def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
233
- if (refs = code.split " + ").size > 1
234
- reltype = "derivedFrom"
235
- reldesc = nil
236
- elsif (refs = code.split ", ").size > 1
237
- reltype = "complements"
238
- reldesc = RelatonBib::FormattedString.new content: "amendment"
239
- else return
240
- end
241
-
242
- doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
243
- ref = refs[0]
244
- updates = check_bibliocache(ref, year, opts, stdclass)
245
- doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates") if updates
246
- refs[1..-1].each_with_object(doc) do |c, d|
247
- bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass)
248
- if bib
249
- d.relation << RelatonBib::DocumentRelation.new(type: reltype, description: reldesc, bibitem: bib)
250
- end
251
- end
252
- end
253
-
254
89
  # @param code [String] code of standard
255
90
  # @return [Symbol] standard class name
256
91
  def standard_class(code)
257
92
  @registry.processors.each do |name, processor|
258
- return name if /^(urn:)?#{processor.prefix}/i.match?(code) ||
93
+ return name if /^#{processor.prefix}/.match(code) ||
259
94
  processor.defaultprefix.match(code)
260
95
  end
261
96
  allowed = @registry.processors.reduce([]) do |m, (_k, v)|
262
97
  m << v.prefix
263
98
  end
264
99
  warn <<~WARN
265
- #{code} does not have a recognised prefix: #{allowed.join(', ')}.
266
- See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
267
- WARN
100
+ #{code} does not have a recognised prefix: #{allowed.join(', ')}.
101
+ See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
102
+ WARN
268
103
  end
269
104
 
270
105
  # TODO: i18n
271
106
  # Fofmat ID
272
107
  # @param code [String]
273
108
  # @param year [String]
274
- #
275
109
  # @param opts [Hash]
276
- # @option opts [Boolean] :all_parts If all-parts reference is required
277
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
278
- # @option opts [Integer] :retries (1) Number of network retries
279
- #
280
110
  # @param stdClass [Symbol]
281
111
  # @return [Array<String>] docid and code
282
112
  def std_id(code, year, opts, stdclass)
@@ -299,36 +129,23 @@ module Relaton
299
129
 
300
130
  # @param entry [String] XML string
301
131
  # @param stdclass [Symbol]
302
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
132
+ # @param id [String] docid
133
+ # @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
303
134
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
304
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
305
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
306
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
307
- # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
308
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
309
- # RelatonW3c::W3cBibliographicItem
310
- def bib_retval(entry, stdclass)
311
- entry.nil? || entry.match?(/^not_found/) ? nil : @registry.processors[stdclass].from_xml(entry)
135
+ # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
136
+ def bib_retval(entry, stdclass, id)
137
+ entry =~ /^not_found/ ? nil : @registry.processors[stdclass].from_xml(entry)
312
138
  end
313
139
 
314
140
  # @param code [String]
315
141
  # @param year [String]
316
- #
317
142
  # @param opts [Hash]
318
- # @option opts [Boolean] :all_parts If all-parts reference is required
319
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
320
- # @option opts [Integer] :retries (1) Number of network retries
321
- #
322
143
  # @param stdclass [Symbol]
323
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
144
+ # @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
324
145
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
325
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
326
146
  # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
327
147
  # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
328
- # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
329
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
330
- # RelatonW3c::W3cBibliographicItem
331
- def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
148
+ def check_bibliocache(code, year, opts, stdclass)
332
149
  id, searchcode = std_id(code, year, opts, stdclass)
333
150
  yaml = @static_db[id]
334
151
  return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml) if yaml
@@ -336,41 +153,31 @@ module Relaton
336
153
  db = @local_db || @db
337
154
  altdb = @local_db && @db ? @db : nil
338
155
  if db.nil?
339
- return if opts[:fetch_db]
340
-
341
156
  bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
342
- return bib_retval(bibentry, stdclass)
157
+ return bib_retval(bibentry, stdclass, id)
343
158
  end
344
159
 
345
160
  db.delete(id) unless db.valid_entry?(id, year)
346
161
  if altdb
347
- return bib_retval(altdb[id], stdclass) if opts[:fetch_db]
348
-
349
- db.clone_entry id, altdb if altdb.valid_entry? id, year
162
+ # db[id] ||= altdb[id]
163
+ db.clone_entry id, altdb
350
164
  db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
351
165
  altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
352
166
  else
353
- return bib_retval(db[id], stdclass) if opts[:fetch_db]
354
-
355
167
  db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
356
168
  end
357
- bib_retval(db[id], stdclass)
169
+ bib_retval(db[id], stdclass, id)
358
170
  end
359
171
 
360
172
  # @param code [String]
361
173
  # @param year [String]
362
- #
363
174
  # @param opts [Hash]
364
- # @option opts [Boolean] :all_parts If all-parts reference is required
365
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
366
- # @option opts [Integer] :retries (1) Number of network retries
367
- #
368
175
  # @param stdclass [Symbol]
369
176
  # @param db [Relaton::DbCache,`NilClass]
370
177
  # @param id [String] docid
371
178
  # @return [String]
372
- def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
373
- bib = net_retry(code, year, opts, stdclass, opts.fetch(:retries, 1))
179
+ def new_bib_entry(code, year, opts, stdclass, **args)
180
+ bib = @registry.processors[stdclass].get(code, year, opts)
374
181
  bib_id = bib&.docidentifier&.first&.id
375
182
 
376
183
  # when docid doesn't match bib's id then return a reference to bib's id
@@ -378,19 +185,11 @@ module Relaton
378
185
  bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
379
186
  args[:db][bid] ||= bib_entry bib
380
187
  "redirection #{bid}"
381
- else bib_entry bib
188
+ else
189
+ bib_entry bib
382
190
  end
383
191
  end
384
192
 
385
- # @raise [RelatonBib::RequestError]
386
- def net_retry(code, year, opts, stdclass, retries)
387
- @registry.processors[stdclass].get(code, year, opts)
388
- rescue RelatonBib::RequestError => e
389
- raise e unless retries > 1
390
-
391
- net_retry(code, year, opts, stdclass, retries - 1)
392
- end
393
-
394
193
  # @param bib [RelatonGb::GbBibliongraphicItem, RelatonIsoBib::IsoBibliographicItem,
395
194
  # RelatonIetf::IetfBibliographicItem, RelatonItu::ItuBibliographicItem,
396
195
  # RelatonNist::NistBibliongraphicItem, RelatonOgc::OgcBibliographicItem]
@@ -403,32 +202,21 @@ module Relaton
403
202
  end
404
203
  end
405
204
 
406
- # @param dir [String, nil] DB directory
205
+ # @param dir [String] DB directory
407
206
  # @param type [Symbol]
408
207
  # @return [Relaton::DbCache, NilClass]
409
208
  def open_cache_biblio(dir, type: :static)
410
209
  return nil if dir.nil?
411
210
 
412
211
  db = DbCache.new dir, type == :static ? "yml" : "xml"
413
- return db if type == :static
414
212
 
415
213
  Dir["#{dir}/*/"].each do |fdir|
416
- next if db.check_version?(fdir)
214
+ next if type == :static || db.check_version?(fdir)
417
215
 
418
- FileUtils.rm_rf(fdir, secure: true)
419
- # db.set_version fdir
216
+ FileUtils.rm_rf(Dir.glob(fdir + "/*"), secure: true)
420
217
  warn "[relaton] cache #{fdir}: version is obsolete and cache is cleared."
421
218
  end
422
219
  db
423
220
  end
424
-
425
- # @param qwp [Hash]
426
- # @option qwp [Queue] :queue The queue of references to fetch
427
- # @option qwp [Relaton::WorkersPool] :workers_pool The pool of workers
428
- def process_queue(qwp)
429
- while args = qwp[:queue].pop
430
- qwp[:workers_pool] << args
431
- end
432
- end
433
221
  end
434
222
  end
@@ -1,5 +1,4 @@
1
1
  require "fileutils"
2
- require "timeout"
3
2
 
4
3
  module Relaton
5
4
  class DbCache
@@ -15,26 +14,6 @@ module Relaton
15
14
  # set_version # unless File.exist? file_version
16
15
  end
17
16
 
18
- # Move caches to anothe dir
19
- # @param new_dir [String, nil]
20
- # @return [String, nil]
21
- def mv(new_dir)
22
- return unless new_dir && @ext == "xml"
23
-
24
- if File.exist? new_dir
25
- warn "[relaton] WARNING: target directory exists \"#{new_dir}\""
26
- return
27
- end
28
-
29
- FileUtils.mv dir, new_dir
30
- @dir = new_dir
31
- end
32
-
33
- # Clear database
34
- def clear
35
- FileUtils.rm_rf Dir.glob "#{dir}/*" if @ext == "xml" # unless it's static DB
36
- end
37
-
38
17
  # Save item
39
18
  # @param key [String]
40
19
  # @param value [String] Bibitem xml serialization
@@ -86,7 +65,7 @@ module Relaton
86
65
  value = self[key]
87
66
  return unless value
88
67
 
89
- if value.match? /^not_found/
68
+ if value =~ /^not_found/
90
69
  value.match(/\d{4}-\d{2}-\d{2}/).to_s
91
70
  else
92
71
  doc = Nokogiri::XML value
@@ -97,9 +76,8 @@ module Relaton
97
76
  # Returns all items
98
77
  # @return [Array<String>]
99
78
  def all
100
- Dir.glob("#{@dir}/**/*.{xml,yml,yaml}").sort.map do |f|
101
- content = File.read(f, encoding: "utf-8")
102
- block_given? ? yield(f, content) : content
79
+ Dir.glob("#{@dir}/**/*.xml").sort.map do |f|
80
+ File.read(f, encoding: "utf-8")
103
81
  end
104
82
  end
105
83
 
@@ -181,7 +159,7 @@ module Relaton
181
159
  def filename(key)
182
160
  prefcode = key.downcase.match /^(?<prefix>[^\(]+)\((?<code>[^\)]+)/
183
161
  fn = if prefcode
184
- "#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/\()]/, '_').squeeze('_')}"
162
+ "#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/\()]/, '_').squeeze("_")}"
185
163
  else
186
164
  key.gsub(/[-:\s]/, "_")
187
165
  end
@@ -215,7 +193,7 @@ module Relaton
215
193
  # @content [String]
216
194
  def file_safe_write(file, content)
217
195
  File.open file, File::RDWR | File::CREAT, encoding: "UTF-8" do |f|
218
- Timeout.timeout(10) { f.flock File::LOCK_EX }
196
+ Timeout.timeout(1) { f.flock File::LOCK_EX }
219
197
  f.write content
220
198
  end
221
199
  end
@@ -240,7 +218,7 @@ module Relaton
240
218
  # local_cache: local cache name; none created if nil; "relaton" created
241
219
  # if empty global_cache: boolean to create global_cache
242
220
  # flush_caches: flush caches
243
- def init_bib_caches(opts) # rubocop:disable Metrics/CyclomaticComplexity
221
+ def init_bib_caches(opts)
244
222
  globalname = global_bibliocache_name if opts[:global_cache]
245
223
  localname = local_bibliocache_name(opts[:local_cache])
246
224
  localname = "relaton" if localname&.empty?
@@ -20,16 +20,5 @@ module Relaton
20
20
  def hash_to_bib(_hash)
21
21
  raise "This is an abstract class!"
22
22
  end
23
-
24
- def grammar_hash
25
- raise "This is an abstract class!"
26
- end
27
-
28
- # Retuns default number of workers. Should be overraded by childred classes if need.
29
- #
30
- # @return [Integer] nuber of wokrers
31
- def threads
32
- 10
33
- end
34
23
  end
35
24
  end
@@ -8,7 +8,7 @@ module Relaton
8
8
  SUPPORTED_GEMS = %w[
9
9
  relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist
10
10
  relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c
11
- relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie
11
+ relaton_ieee relaton_iho relaton_bipm
12
12
  ].freeze
13
13
 
14
14
  include Singleton
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.7.pre7".freeze
2
+ VERSION = "1.7.0".freeze
3
3
  end
data/lib/relaton.rb CHANGED
@@ -1,9 +1,8 @@
1
- require "relaton/util"
2
- require "relaton/config"
1
+ require_relative "relaton/util"
2
+ require_relative "relaton/config"
3
3
 
4
- require "relaton/workers_pool"
5
- require "relaton/db"
6
- require "relaton/db_cache"
7
- require "relaton/version"
8
- require "relaton/registry"
9
- require "relaton/processor"
4
+ require_relative "relaton/db"
5
+ require_relative "relaton/db_cache"
6
+ require_relative "relaton/version"
7
+ require_relative "relaton/registry"
8
+ require_relative "relaton/processor"
data/relaton.gemspec CHANGED
@@ -32,23 +32,21 @@ Gem::Specification.new do |spec|
32
32
  # spec.add_dependency "algoliasearch"
33
33
  spec.add_dependency "relaton-bipm", "~> 1.7.0"
34
34
  spec.add_dependency "relaton-calconnect", "~> 1.7.0"
35
- spec.add_dependency "relaton-cie", "~> 1.7.pre1"
36
- spec.add_dependency "relaton-ecma", "~> 1.7.pre1"
37
35
  spec.add_dependency "relaton-gb", "~> 1.7.0"
38
- spec.add_dependency "relaton-iec", ">= 1.7.6"
36
+ spec.add_dependency "relaton-iec", "~> 1.7.0"
39
37
  spec.add_dependency "relaton-ieee", "~> 1.7.0"
40
38
  spec.add_dependency "relaton-ietf", "~> 1.7.0"
41
39
  spec.add_dependency "relaton-iho", "~> 1.7.0"
42
- spec.add_dependency "relaton-iso", ">= 1.7.1"
43
- spec.add_dependency "relaton-itu", ">= 1.7.2"
44
- spec.add_dependency "relaton-nist", ">= 1.7.1"
40
+ spec.add_dependency "relaton-iso", "~> 1.7.0"
41
+ spec.add_dependency "relaton-itu", "~> 1.7.0"
42
+ spec.add_dependency "relaton-nist", "~> 1.7.0"
45
43
  spec.add_dependency "relaton-ogc", "~> 1.7.0"
46
44
  spec.add_dependency "relaton-omg", "~> 1.7.0"
47
45
  spec.add_dependency "relaton-un", "~> 1.7.0"
48
46
  spec.add_dependency "relaton-w3c", "~> 1.7.0"
49
47
 
50
48
  spec.add_development_dependency "byebug", "~> 11.0"
51
- # spec.add_development_dependency "debase"
49
+ spec.add_development_dependency "debase"
52
50
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
53
51
  spec.add_development_dependency "guard", "~> 2.14"
54
52
  spec.add_development_dependency "guard-rspec", "~> 4.7"
@@ -56,7 +54,7 @@ Gem::Specification.new do |spec|
56
54
  spec.add_development_dependency "rake", "~> 10.0"
57
55
  spec.add_development_dependency "rspec", "~> 3.6"
58
56
  spec.add_development_dependency "rubocop", "= 0.54.0"
59
- # spec.add_development_dependency "ruby-debug-ide"
57
+ spec.add_development_dependency "ruby-debug-ide"
60
58
  spec.add_development_dependency "simplecov", "~> 0.15"
61
59
  spec.add_development_dependency "timecop", "~> 0.9"
62
60
  spec.add_development_dependency "vcr", "~> 5"
@@ -7,7 +7,7 @@ RSpec.describe Relaton::DbCache do
7
7
  FileUtils.mv cache_path, "relaton1/cache", force: true
8
8
  FileUtils.rm_rf %w(relaton)
9
9
  Relaton::DbCache.init_bib_caches(
10
- global_cache: true, local_cache: "", flush_caches: true
10
+ global_cache: true, local_cache: "", flush_caches: true,
11
11
  )
12
12
  expect(File.exist?(cache_path)).to be true
13
13
  expect(File.exist?("relaton")).to be true