relaton 1.7.6 → 1.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/README.adoc +10 -6
- data/lib/relaton/config.rb +4 -2
- data/lib/relaton/db.rb +123 -76
- data/lib/relaton/db_cache.rb +6 -0
- data/lib/relaton/util.rb +1 -1
- data/lib/relaton/version.rb +1 -1
- data/relaton.gemspec +1 -1
- data/spec/relaton/config_spec.rb +1 -1
- data/spec/relaton/db_spec.rb +34 -11
- data/spec/relaton/regirtry_spec.rb +1 -1
- data/spec/relaton_spec.rb +4 -4
- data/spec/vcr_cassetes/19133_2005.yml +20 -20
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +10 -10
- data/spec/vcr_cassetes/cie_001_1980.yml +7 -7
- data/spec/vcr_cassetes/ecma_6.yml +7 -7
- data/spec/vcr_cassetes/fisp_140.yml +4 -4
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +6 -6
- data/spec/vcr_cassetes/iec_60050_102_2007.yml +29 -27
- data/spec/vcr_cassetes/iec_combined_included.yml +69 -69
- data/spec/vcr_cassetes/ieee_528_2019.yml +20 -20
- data/spec/vcr_cassetes/iho_b_11.yml +7 -7
- data/spec/vcr_cassetes/iso_111111119115_1.yml +5 -5
- data/spec/vcr_cassetes/iso_19115.yml +21 -21
- data/spec/vcr_cassetes/iso_19115_1.yml +20 -20
- data/spec/vcr_cassetes/iso_19115_1_2.yml +40 -40
- data/spec/vcr_cassetes/iso_awi_24229.yml +21 -21
- data/spec/vcr_cassetes/iso_combined_applied.yml +43 -43
- data/spec/vcr_cassetes/iso_combined_included.yml +40 -40
- data/spec/vcr_cassetes/itu_combined_included.yml +85 -85
- data/spec/vcr_cassetes/ogc_19_025r1.yml +1214 -1147
- data/spec/vcr_cassetes/ogm_ami4ccm_1_0.yml +6 -6
- data/spec/vcr_cassetes/rfc_8341.yml +7 -7
- data/spec/vcr_cassetes/sp_800_38b.yml +4 -4
- data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +29 -29
- data/spec/vcr_cassetes/w3c_json_ld11.yml +12 -12
- metadata +5 -7
- data/localcache/iec/iec_60050_102_2007.xml +0 -58
- data/localcache/iec/version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5814864d64a95c8d7cb4fbb094b2e789cf4f7b731ebc8a2e1f41a7cdbbce2115
|
4
|
+
data.tar.gz: 57319c212c34e9ff237b0f834eaad40f3d173dc3de784acd4a5ea804bc11ae01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '097fcda0d2884380cbb6b64bdcbc43f38215036921177e897c5962274885456a49a323ea4c02a7a548bfb696cba261d1aac0e7ad7dfc51abe698d9d117b715b5'
|
7
|
+
data.tar.gz: 0052e5b6696c790e7deb6d17dd7b12a2918b452f93101cda548c96316317988a061a6aabe8c1277fdc69c45f9bfa2f3af2ab6f862adee48efa0504641d3035c1
|
data/docs/README.adoc
CHANGED
@@ -106,14 +106,18 @@ db = Relaton::Db.new("globalcache", "localcache")
|
|
106
106
|
|
107
107
|
==== Move DB
|
108
108
|
|
109
|
-
`Relaton::Db#mv(
|
109
|
+
`Relaton::Db#mv(new_dir, type: :global)` moves DB directory to new location. Returns path to new directory if successful, or `nil` if target directiory exists.
|
110
110
|
|
111
|
-
* `
|
112
|
-
* `
|
111
|
+
* `new_dir` - (String) new cache location
|
112
|
+
* `type` - (Symbol) type of cache DB. Allowed values are: `:global`, `:local`. Default is `:global`.
|
113
113
|
|
114
114
|
[source,ruby]
|
115
115
|
----
|
116
|
-
db.mv("
|
116
|
+
db.mv("new_global_dir")
|
117
|
+
=> "new_global_dir"
|
118
|
+
|
119
|
+
db.mv("new_local_dir", type: :local)
|
120
|
+
=> "new_local_dir"
|
117
121
|
----
|
118
122
|
|
119
123
|
==== Clear DB
|
@@ -330,7 +334,7 @@ ISO/IEC DIR 1
|
|
330
334
|
ISO/IEC DIR 2 IEC
|
331
335
|
ISO/IEC DIR 2 ISO
|
332
336
|
ISO/IEC DIR IEC SUP
|
333
|
-
ISO/IEC DIR 1
|
337
|
+
ISO/IEC DIR 1 JTC SUP
|
334
338
|
----
|
335
339
|
|
336
340
|
=== Get document type
|
@@ -368,7 +372,7 @@ x.to_xml bibdata: true
|
|
368
372
|
db.load_entry("ISO(ISO 19011)")
|
369
373
|
=> "<bibdata type="standard">
|
370
374
|
...
|
371
|
-
|
375
|
+
</bibdata>"
|
372
376
|
----
|
373
377
|
|
374
378
|
=== Entry manipulation
|
data/lib/relaton/config.rb
CHANGED
@@ -15,8 +15,10 @@ module Relaton
|
|
15
15
|
attr_accessor :logs, :use_api
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
@logs = %i(
|
19
|
-
|
18
|
+
@logs = %i(info error)
|
19
|
+
|
20
|
+
# @TODO change to true when we start using api.relaton.org
|
21
|
+
@use_api = false
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
data/lib/relaton/db.rb
CHANGED
@@ -10,51 +10,64 @@ 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
|
-
|
14
|
-
@
|
15
|
-
|
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",
|
18
|
+
__dir__)
|
16
19
|
@queues = {}
|
17
20
|
end
|
18
21
|
|
19
|
-
# Move global
|
20
|
-
# @param
|
21
|
-
# @param
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
# Move global or local caches to anothe dirs
|
23
|
+
# @param new_dir [String, nil]
|
24
|
+
# @param type: [Symbol]
|
25
|
+
# @return [String, nil]
|
26
|
+
def mv(new_dir, type: :global)
|
27
|
+
case type
|
28
|
+
when :global
|
29
|
+
@db&.mv new_dir
|
30
|
+
when :local
|
31
|
+
@local_db&.mv new_dir
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
# Clear global and local databases
|
28
36
|
def clear
|
29
|
-
@db
|
30
|
-
@local_db
|
37
|
+
@db&.clear
|
38
|
+
@local_db&.clear
|
31
39
|
end
|
32
40
|
|
33
41
|
##
|
34
42
|
# The class of reference requested is determined by the prefix of the code:
|
35
|
-
# GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for
|
43
|
+
# GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for
|
44
|
+
# iecbib,
|
36
45
|
#
|
37
46
|
# @param code [String] the ISO standard Code to look up (e.g. "ISO 9000")
|
38
47
|
# @param year [String] the year the standard was published (optional)
|
39
48
|
#
|
40
49
|
# @param opts [Hash] options
|
41
50
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
42
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
51
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
52
|
+
# actual reference with year
|
43
53
|
# @option opts [Integer] :retries (1) Number of network retries
|
44
54
|
#
|
45
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# RelatonOgc::OgcBibliographicItem,
|
55
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
56
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
57
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
58
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
59
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
60
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
50
61
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
51
|
-
# RelatonOmg::OmgBibliographicItem
|
52
|
-
# RelatonW3c::W3cBibliographicItem
|
62
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
53
63
|
##
|
54
64
|
def fetch(code, year = nil, opts = {})
|
55
65
|
stdclass = standard_class(code) || return
|
56
66
|
processor = @registry.processors[stdclass]
|
57
|
-
ref = processor.respond_to?(:urn_to_code)
|
67
|
+
ref = if processor.respond_to?(:urn_to_code)
|
68
|
+
processor.urn_to_code(code)&.first
|
69
|
+
else code
|
70
|
+
end
|
58
71
|
ref ||= code
|
59
72
|
result = combine_doc ref, year, opts, stdclass
|
60
73
|
result ||= check_bibliocache(ref, year, opts, stdclass)
|
@@ -73,9 +86,15 @@ module Relaton
|
|
73
86
|
# @param year [Integer, nil]
|
74
87
|
# @return [Array]
|
75
88
|
def fetch_all(text = nil, edition: nil, year: nil)
|
76
|
-
result = @static_db.all
|
89
|
+
result = @static_db.all do |file, yml|
|
90
|
+
search_yml file, yml, text, edition, year
|
91
|
+
end.compact
|
77
92
|
db = @db || @local_db
|
78
|
-
|
93
|
+
if db
|
94
|
+
result += db.all do |file, xml|
|
95
|
+
search_xml file, xml, text, edition, year
|
96
|
+
end.compact
|
97
|
+
end
|
79
98
|
result
|
80
99
|
end
|
81
100
|
|
@@ -100,17 +119,18 @@ module Relaton
|
|
100
119
|
#
|
101
120
|
# @param opts [Hash]
|
102
121
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
103
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
122
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
123
|
+
# actual reference with year
|
104
124
|
# @option opts [Integer] :retries (1) Number of network retries
|
105
125
|
#
|
106
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
# RelatonOgc::OgcBibliographicItem,
|
126
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
127
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
128
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
129
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
130
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
131
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
111
132
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
112
|
-
# RelatonOmg::OmgBibliographicItem
|
113
|
-
# RelatonW3c::W3cBibliographicItem
|
133
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
114
134
|
def fetch_std(code, year = nil, stdclass = nil, opts = {})
|
115
135
|
std = nil
|
116
136
|
@registry.processors.each do |name, processor|
|
@@ -193,9 +213,11 @@ module Relaton
|
|
193
213
|
# @return [BibliographicItem, nil]
|
194
214
|
def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
195
215
|
processor = @registry.processors[standard_class(file.split("/")[-2])]
|
196
|
-
item = file.match?(/xml$/)
|
197
|
-
|
198
|
-
|
216
|
+
item = if file.match?(/xml$/) then processor.from_xml(content)
|
217
|
+
else processor.hash_to_bib(YAML.safe_load(content))
|
218
|
+
end
|
219
|
+
item if (edition.nil? || item.edition == edition) && (year.nil? ||
|
220
|
+
item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s })
|
199
221
|
end
|
200
222
|
|
201
223
|
# @param xml [String] content in XML format
|
@@ -211,17 +233,18 @@ module Relaton
|
|
211
233
|
#
|
212
234
|
# @param opts [Hash] options
|
213
235
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
214
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
236
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
237
|
+
# actual reference with year
|
215
238
|
# @option opts [Integer] :retries (1) Number of network retries
|
216
239
|
#
|
217
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
# RelatonOgc::OgcBibliographicItem,
|
240
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
241
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
242
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
243
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
244
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
245
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
222
246
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
223
|
-
# RelatonOmg::OmgBibliographicItem
|
224
|
-
# RelatonW3c::W3cBibliographicItem
|
247
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
225
248
|
def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
226
249
|
if (refs = code.split " + ").size > 1
|
227
250
|
reltype = "derivedFrom"
|
@@ -235,11 +258,16 @@ module Relaton
|
|
235
258
|
doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
|
236
259
|
ref = refs[0]
|
237
260
|
updates = check_bibliocache(ref, year, opts, stdclass)
|
238
|
-
|
261
|
+
if updates
|
262
|
+
doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates,
|
263
|
+
type: "updates")
|
264
|
+
end
|
239
265
|
refs[1..-1].each_with_object(doc) do |c, d|
|
240
266
|
bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass)
|
241
267
|
if bib
|
242
|
-
d.relation << RelatonBib::DocumentRelation.new(
|
268
|
+
d.relation << RelatonBib::DocumentRelation.new(
|
269
|
+
type: reltype, description: reldesc, bibitem: bib
|
270
|
+
)
|
243
271
|
end
|
244
272
|
end
|
245
273
|
end
|
@@ -254,8 +282,8 @@ module Relaton
|
|
254
282
|
allowed = @registry.processors.reduce([]) do |m, (_k, v)|
|
255
283
|
m << v.prefix
|
256
284
|
end
|
257
|
-
|
258
|
-
#{code} does not have a recognised prefix: #{allowed.join(', ')}.
|
285
|
+
Util.log <<~WARN, :info
|
286
|
+
[relaton] #{code} does not have a recognised prefix: #{allowed.join(', ')}.
|
259
287
|
See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
|
260
288
|
WARN
|
261
289
|
end
|
@@ -267,7 +295,8 @@ module Relaton
|
|
267
295
|
#
|
268
296
|
# @param opts [Hash]
|
269
297
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
270
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
298
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
299
|
+
# actual reference with year
|
271
300
|
# @option opts [Integer] :retries (1) Number of network retries
|
272
301
|
#
|
273
302
|
# @param stdClass [Symbol]
|
@@ -292,16 +321,18 @@ module Relaton
|
|
292
321
|
|
293
322
|
# @param entry [String] XML string
|
294
323
|
# @param stdclass [Symbol]
|
295
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
# RelatonOgc::OgcBibliographicItem,
|
324
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
325
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
326
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
327
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
328
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
329
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
300
330
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
301
|
-
# RelatonOmg::OmgBibliographicItem
|
302
|
-
# RelatonW3c::W3cBibliographicItem
|
331
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
303
332
|
def bib_retval(entry, stdclass)
|
304
|
-
entry.nil? || entry.match?(/^not_found/)
|
333
|
+
if entry.nil? || entry.match?(/^not_found/) then nil
|
334
|
+
else @registry.processors[stdclass].from_xml(entry)
|
335
|
+
end
|
305
336
|
end
|
306
337
|
|
307
338
|
# @param code [String]
|
@@ -309,29 +340,33 @@ module Relaton
|
|
309
340
|
#
|
310
341
|
# @param opts [Hash]
|
311
342
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
312
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
343
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
344
|
+
# actual reference with year
|
313
345
|
# @option opts [Integer] :retries (1) Number of network retries
|
314
346
|
#
|
315
347
|
# @param stdclass [Symbol]
|
316
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
# RelatonOgc::OgcBibliographicItem,
|
348
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
349
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
350
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
351
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
352
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
353
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
321
354
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
322
|
-
# RelatonOmg::OmgBibliographicItem
|
323
|
-
# RelatonW3c::W3cBibliographicItem
|
355
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
324
356
|
def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
325
357
|
id, searchcode = std_id(code, year, opts, stdclass)
|
326
358
|
yaml = @static_db[id]
|
327
|
-
|
359
|
+
if yaml
|
360
|
+
return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml)
|
361
|
+
end
|
328
362
|
|
329
363
|
db = @local_db || @db
|
330
364
|
altdb = @local_db && @db ? @db : nil
|
331
365
|
if db.nil?
|
332
366
|
return if opts[:fetch_db]
|
333
367
|
|
334
|
-
bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
368
|
+
bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
369
|
+
id: id)
|
335
370
|
return bib_retval(bibentry, stdclass)
|
336
371
|
end
|
337
372
|
|
@@ -340,12 +375,14 @@ module Relaton
|
|
340
375
|
return bib_retval(altdb[id], stdclass) if opts[:fetch_db]
|
341
376
|
|
342
377
|
db.clone_entry id, altdb if altdb.valid_entry? id, year
|
343
|
-
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
378
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
379
|
+
id: id)
|
344
380
|
altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
|
345
381
|
else
|
346
382
|
return bib_retval(db[id], stdclass) if opts[:fetch_db]
|
347
383
|
|
348
|
-
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
384
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
385
|
+
id: id)
|
349
386
|
end
|
350
387
|
bib_retval(db[id], stdclass)
|
351
388
|
end
|
@@ -355,7 +392,8 @@ module Relaton
|
|
355
392
|
#
|
356
393
|
# @param opts [Hash]
|
357
394
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
358
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
395
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
396
|
+
# actual reference with year
|
359
397
|
# @option opts [Integer] :retries (1) Number of network retries
|
360
398
|
#
|
361
399
|
# @param stdclass [Symbol]
|
@@ -367,7 +405,8 @@ module Relaton
|
|
367
405
|
bib_id = bib&.docidentifier&.first&.id
|
368
406
|
|
369
407
|
# when docid doesn't match bib's id then return a reference to bib's id
|
370
|
-
if args[:db] && args[:id] &&
|
408
|
+
if args[:db] && args[:id] &&
|
409
|
+
bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
|
371
410
|
bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
|
372
411
|
args[:db][bid] ||= bib_entry bib
|
373
412
|
"redirection #{bid}"
|
@@ -384,9 +423,14 @@ module Relaton
|
|
384
423
|
net_retry(code, year, opts, stdclass, retries - 1)
|
385
424
|
end
|
386
425
|
|
387
|
-
# @param bib [
|
388
|
-
#
|
389
|
-
#
|
426
|
+
# @param bib [RelatonBib::BibliographicItem,
|
427
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
428
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
429
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
430
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
431
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
432
|
+
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
433
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
390
434
|
# @return [String] XML or "not_found mm-dd-yyyy"
|
391
435
|
def bib_entry(bib)
|
392
436
|
if bib.respond_to? :to_xml
|
@@ -399,7 +443,7 @@ module Relaton
|
|
399
443
|
# @param dir [String, nil] DB directory
|
400
444
|
# @param type [Symbol]
|
401
445
|
# @return [Relaton::DbCache, NilClass]
|
402
|
-
def open_cache_biblio(dir, type: :static)
|
446
|
+
def open_cache_biblio(dir, type: :static) # rubocop:disable Metrics/MethodLength
|
403
447
|
return nil if dir.nil?
|
404
448
|
|
405
449
|
db = DbCache.new dir, type == :static ? "yml" : "xml"
|
@@ -408,9 +452,12 @@ module Relaton
|
|
408
452
|
Dir["#{dir}/*/"].each do |fdir|
|
409
453
|
next if db.check_version?(fdir)
|
410
454
|
|
411
|
-
FileUtils.rm_rf(
|
412
|
-
|
413
|
-
|
455
|
+
FileUtils.rm_rf(fdir, secure: true)
|
456
|
+
Util.log(
|
457
|
+
"[relaton] WARNING: cache #{fdir}: version is obsolete and cache is "\
|
458
|
+
"cleared.",
|
459
|
+
:warning
|
460
|
+
)
|
414
461
|
end
|
415
462
|
db
|
416
463
|
end
|
data/lib/relaton/db_cache.rb
CHANGED
@@ -17,9 +17,15 @@ module Relaton
|
|
17
17
|
|
18
18
|
# Move caches to anothe dir
|
19
19
|
# @param new_dir [String, nil]
|
20
|
+
# @return [String, nil]
|
20
21
|
def mv(new_dir)
|
21
22
|
return unless new_dir && @ext == "xml"
|
22
23
|
|
24
|
+
if File.exist? new_dir
|
25
|
+
warn "[relaton] WARNING: target directory exists \"#{new_dir}\""
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
23
29
|
FileUtils.mv dir, new_dir
|
24
30
|
@dir = new_dir
|
25
31
|
end
|