relaton 1.7.4 → 1.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +46 -0
- data/docs/README.adoc +20 -11
- data/lib/relaton/config.rb +4 -2
- data/lib/relaton/db.rb +127 -81
- data/lib/relaton/db_cache.rb +6 -0
- data/lib/relaton/registry.rb +2 -2
- data/lib/relaton/util.rb +3 -1
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton/workers_pool.rb +1 -3
- data/relaton.gemspec +6 -4
- data/spec/relaton/config_spec.rb +1 -1
- data/spec/relaton/db_spec.rb +48 -16
- data/spec/relaton/regirtry_spec.rb +51 -45
- data/spec/relaton_spec.rb +20 -6
- data/spec/vcr_cassetes/19133_2005.yml +21 -21
- data/spec/vcr_cassetes/async_fetch.yml +4423 -0
- data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +159 -0
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +10 -10
- data/spec/vcr_cassetes/cie_001_1980.yml +120 -0
- data/spec/vcr_cassetes/ecma_6.yml +133 -68
- 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 +30 -26
- data/spec/vcr_cassetes/iec_combined_included.yml +74 -80
- data/spec/vcr_cassetes/ieee_528_2019.yml +41 -39
- 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 +22 -22
- data/spec/vcr_cassetes/iso_19115_1.yml +21 -21
- data/spec/vcr_cassetes/iso_19115_1_2.yml +43 -43
- data/spec/vcr_cassetes/iso_awi_24229.yml +22 -22
- data/spec/vcr_cassetes/iso_combined_applied.yml +43 -43
- data/spec/vcr_cassetes/iso_combined_included.yml +41 -41
- data/spec/vcr_cassetes/itu_combined_included.yml +527 -392
- data/spec/vcr_cassetes/ogc_19_025r1.yml +1425 -1125
- data/spec/vcr_cassetes/ogm_ami4ccm_1_0.yml +11 -23
- 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 +34 -38
- data/spec/vcr_cassetes/w3c_json_ld11.yml +12 -12
- metadata +38 -39
- data/.github/workflows/macos.yml +0 -34
- data/.github/workflows/ubuntu.yml +0 -32
- data/.github/workflows/windows.yml +0 -35
- 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: 1b14a266fd6fd230fc37d8e2e6843bd48c37019136dc6006a27a89668ecf7af2
|
4
|
+
data.tar.gz: 3eb6ba9aaa798ab5b763328712e4051184ff2c9de1659791198ca8a7a21726c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a0f6f87426975dbf87e9eefd69d3f519e3a178452039eb9d036725e4c7bdd676ebe0d228a07b3512d296b6d4153cc1e88c72589baa702fb8ac1de717204783
|
7
|
+
data.tar.gz: e748db6725c7d027b38e1140dc60d74cdea86304f2380d9251cc9d07f143d0536e4b7e1bb63dea35ddd464e2969e08c03f6cde10a426f19e0a8959ecf7a6281f
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '3.0'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '3.0'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '3.0'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
with:
|
35
|
+
submodules: true
|
36
|
+
|
37
|
+
# https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
|
38
|
+
- if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
|
39
|
+
run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
|
40
|
+
|
41
|
+
- uses: ruby/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
44
|
+
bundler-cache: true
|
45
|
+
|
46
|
+
- run: bundle exec rake
|
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
|
@@ -178,14 +182,19 @@ x = db.fetch_db("ISO 5749")
|
|
178
182
|
# prepare queue for results
|
179
183
|
results = Queue.new
|
180
184
|
|
181
|
-
# fetch
|
182
|
-
|
183
|
-
|
185
|
+
# references ot fetch
|
186
|
+
refs = ["ISO 19011", "ISO 19115"]
|
187
|
+
|
188
|
+
# fetch documents
|
189
|
+
refs.each do |ref|
|
190
|
+
db.fetch_async(ref) do |doc|
|
191
|
+
results << [ref, doc]
|
192
|
+
end
|
184
193
|
end
|
185
|
-
# fetch other documets the same way
|
186
194
|
|
187
195
|
# wait until documets fetching
|
188
|
-
|
196
|
+
refs.size.times do
|
197
|
+
ref, doc = results.pop
|
189
198
|
# do thatever you need with result x
|
190
199
|
end
|
191
200
|
----
|
@@ -330,7 +339,7 @@ ISO/IEC DIR 1
|
|
330
339
|
ISO/IEC DIR 2 IEC
|
331
340
|
ISO/IEC DIR 2 ISO
|
332
341
|
ISO/IEC DIR IEC SUP
|
333
|
-
ISO/IEC DIR 1
|
342
|
+
ISO/IEC DIR 1 JTC SUP
|
334
343
|
----
|
335
344
|
|
336
345
|
=== Get document type
|
@@ -368,7 +377,7 @@ x.to_xml bibdata: true
|
|
368
377
|
db.load_entry("ISO(ISO 19011)")
|
369
378
|
=> "<bibdata type="standard">
|
370
379
|
...
|
371
|
-
|
380
|
+
</bibdata>"
|
372
381
|
----
|
373
382
|
|
374
383
|
=== 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(warning error
|
19
|
-
|
18
|
+
@logs = %i(info error) # allowed values: :info, :warning, :error, :debug
|
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,18 +233,19 @@ 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
|
-
#
|
225
|
-
def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
247
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
248
|
+
def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
226
249
|
if (refs = code.split " + ").size > 1
|
227
250
|
reltype = "derivedFrom"
|
228
251
|
reldesc = nil
|
@@ -235,11 +258,17 @@ 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
|
265
|
+
divider = stdclass == :relaton_itu ? " " : "/"
|
239
266
|
refs[1..-1].each_with_object(doc) do |c, d|
|
240
|
-
bib = check_bibliocache(
|
267
|
+
bib = check_bibliocache(ref + divider + c, year, opts, stdclass)
|
241
268
|
if bib
|
242
|
-
d.relation << RelatonBib::DocumentRelation.new(
|
269
|
+
d.relation << RelatonBib::DocumentRelation.new(
|
270
|
+
type: reltype, description: reldesc, bibitem: bib
|
271
|
+
)
|
243
272
|
end
|
244
273
|
end
|
245
274
|
end
|
@@ -254,8 +283,8 @@ module Relaton
|
|
254
283
|
allowed = @registry.processors.reduce([]) do |m, (_k, v)|
|
255
284
|
m << v.prefix
|
256
285
|
end
|
257
|
-
|
258
|
-
#{code} does not have a recognised prefix: #{allowed.join(', ')}.
|
286
|
+
Util.log <<~WARN, :info
|
287
|
+
[relaton] #{code} does not have a recognised prefix: #{allowed.join(', ')}.
|
259
288
|
See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
|
260
289
|
WARN
|
261
290
|
end
|
@@ -267,7 +296,8 @@ module Relaton
|
|
267
296
|
#
|
268
297
|
# @param opts [Hash]
|
269
298
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
270
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
299
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
300
|
+
# actual reference with year
|
271
301
|
# @option opts [Integer] :retries (1) Number of network retries
|
272
302
|
#
|
273
303
|
# @param stdClass [Symbol]
|
@@ -292,16 +322,18 @@ module Relaton
|
|
292
322
|
|
293
323
|
# @param entry [String] XML string
|
294
324
|
# @param stdclass [Symbol]
|
295
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
# RelatonOgc::OgcBibliographicItem,
|
325
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
326
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
327
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
328
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
329
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
330
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
300
331
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
301
|
-
# RelatonOmg::OmgBibliographicItem
|
302
|
-
# RelatonW3c::W3cBibliographicItem
|
332
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
303
333
|
def bib_retval(entry, stdclass)
|
304
|
-
entry.nil? || entry.match?(/^not_found/)
|
334
|
+
if entry.nil? || entry.match?(/^not_found/) then nil
|
335
|
+
else @registry.processors[stdclass].from_xml(entry)
|
336
|
+
end
|
305
337
|
end
|
306
338
|
|
307
339
|
# @param code [String]
|
@@ -309,29 +341,33 @@ module Relaton
|
|
309
341
|
#
|
310
342
|
# @param opts [Hash]
|
311
343
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
312
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
344
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
345
|
+
# actual reference with year
|
313
346
|
# @option opts [Integer] :retries (1) Number of network retries
|
314
347
|
#
|
315
348
|
# @param stdclass [Symbol]
|
316
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
# RelatonOgc::OgcBibliographicItem,
|
349
|
+
# @return [nil, RelatonBib::BibliographicItem,
|
350
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
351
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
352
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
353
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
354
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
321
355
|
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
322
|
-
# RelatonOmg::OmgBibliographicItem
|
323
|
-
# RelatonW3c::W3cBibliographicItem
|
356
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
324
357
|
def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
325
358
|
id, searchcode = std_id(code, year, opts, stdclass)
|
326
359
|
yaml = @static_db[id]
|
327
|
-
|
360
|
+
if yaml
|
361
|
+
return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml)
|
362
|
+
end
|
328
363
|
|
329
364
|
db = @local_db || @db
|
330
365
|
altdb = @local_db && @db ? @db : nil
|
331
366
|
if db.nil?
|
332
367
|
return if opts[:fetch_db]
|
333
368
|
|
334
|
-
bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
369
|
+
bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
370
|
+
id: id)
|
335
371
|
return bib_retval(bibentry, stdclass)
|
336
372
|
end
|
337
373
|
|
@@ -340,12 +376,14 @@ module Relaton
|
|
340
376
|
return bib_retval(altdb[id], stdclass) if opts[:fetch_db]
|
341
377
|
|
342
378
|
db.clone_entry id, altdb if altdb.valid_entry? id, year
|
343
|
-
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
379
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
380
|
+
id: id)
|
344
381
|
altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
|
345
382
|
else
|
346
383
|
return bib_retval(db[id], stdclass) if opts[:fetch_db]
|
347
384
|
|
348
|
-
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
385
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
|
386
|
+
id: id)
|
349
387
|
end
|
350
388
|
bib_retval(db[id], stdclass)
|
351
389
|
end
|
@@ -355,7 +393,8 @@ module Relaton
|
|
355
393
|
#
|
356
394
|
# @param opts [Hash]
|
357
395
|
# @option opts [Boolean] :all_parts If all-parts reference is required
|
358
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
396
|
+
# @option opts [Boolean] :keep_year If undated reference should return
|
397
|
+
# actual reference with year
|
359
398
|
# @option opts [Integer] :retries (1) Number of network retries
|
360
399
|
#
|
361
400
|
# @param stdclass [Symbol]
|
@@ -367,7 +406,8 @@ module Relaton
|
|
367
406
|
bib_id = bib&.docidentifier&.first&.id
|
368
407
|
|
369
408
|
# when docid doesn't match bib's id then return a reference to bib's id
|
370
|
-
if args[:db] && args[:id] &&
|
409
|
+
if args[:db] && args[:id] &&
|
410
|
+
bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
|
371
411
|
bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
|
372
412
|
args[:db][bid] ||= bib_entry bib
|
373
413
|
"redirection #{bid}"
|
@@ -384,9 +424,14 @@ module Relaton
|
|
384
424
|
net_retry(code, year, opts, stdclass, retries - 1)
|
385
425
|
end
|
386
426
|
|
387
|
-
# @param bib [
|
388
|
-
#
|
389
|
-
#
|
427
|
+
# @param bib [RelatonBib::BibliographicItem,
|
428
|
+
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
429
|
+
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
430
|
+
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
431
|
+
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
432
|
+
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
433
|
+
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
434
|
+
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
390
435
|
# @return [String] XML or "not_found mm-dd-yyyy"
|
391
436
|
def bib_entry(bib)
|
392
437
|
if bib.respond_to? :to_xml
|
@@ -399,7 +444,7 @@ module Relaton
|
|
399
444
|
# @param dir [String, nil] DB directory
|
400
445
|
# @param type [Symbol]
|
401
446
|
# @return [Relaton::DbCache, NilClass]
|
402
|
-
def open_cache_biblio(dir, type: :static)
|
447
|
+
def open_cache_biblio(dir, type: :static) # rubocop:disable Metrics/MethodLength
|
403
448
|
return nil if dir.nil?
|
404
449
|
|
405
450
|
db = DbCache.new dir, type == :static ? "yml" : "xml"
|
@@ -408,9 +453,12 @@ module Relaton
|
|
408
453
|
Dir["#{dir}/*/"].each do |fdir|
|
409
454
|
next if db.check_version?(fdir)
|
410
455
|
|
411
|
-
FileUtils.rm_rf(
|
412
|
-
|
413
|
-
|
456
|
+
FileUtils.rm_rf(fdir, secure: true)
|
457
|
+
Util.log(
|
458
|
+
"[relaton] WARNING: cache #{fdir}: version is obsolete and cache is "\
|
459
|
+
"cleared.",
|
460
|
+
:warning
|
461
|
+
)
|
414
462
|
end
|
415
463
|
db
|
416
464
|
end
|
@@ -419,9 +467,7 @@ module Relaton
|
|
419
467
|
# @option qwp [Queue] :queue The queue of references to fetch
|
420
468
|
# @option qwp [Relaton::WorkersPool] :workers_pool The pool of workers
|
421
469
|
def process_queue(qwp)
|
422
|
-
while args = qwp[:queue].pop
|
423
|
-
qwp[:workers_pool] << args
|
424
|
-
end
|
470
|
+
while args = qwp[:queue].pop; qwp[:workers_pool] << args end
|
425
471
|
end
|
426
472
|
end
|
427
473
|
end
|