relaton 0.1.3 → 0.1.4
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/Gemfile.lock +12 -12
- data/lib/relaton/db.rb +34 -15
- data/lib/relaton/version.rb +1 -1
- data/relaton.gemspec +2 -2
- data/spec/relaton/relaton_spec.rb +31 -16
- data/spec/support/gb_t_20223_2006 +0 -0
- data/spec/support/iso_19115_1 +0 -0
- data/spec/support/iso_19115_2 +0 -0
- data/spec/support/rfc_8341 +0 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fe630fa3e1b71d5015cb2585ddde54e3dfeb0b50557c9c21b8d99cf29d284f5
|
4
|
+
data.tar.gz: dc21bfb4dda47648077f5195bd3b5fdd84cab5f7b9b62a77aa79422f4057476e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bf91d95623237aa5d3915023d7dbe1d872988d11c44f202e7f6924443f5caca31ad232a747415f77e1a2f9aee077664983b0c373841bb669706f294b42a1117
|
7
|
+
data.tar.gz: f43db773f05d5975d04d17bcdbb4a049b8b0c73446c8332ac82d3031dec4fab267ed352ad5df09eac4fcc211ca564268144fbd3380dfee9b436e9a595c727c97
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relaton (0.1.
|
4
|
+
relaton (0.1.4)
|
5
5
|
algoliasearch
|
6
6
|
gbbib (~> 0.2.1)
|
7
|
-
|
7
|
+
iso-bib-item (~> 0.2.3)
|
8
8
|
isobib (~> 0.2.0)
|
9
|
-
rfcbib (~> 0.2.
|
9
|
+
rfcbib (~> 0.2.2)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
json (>= 1.5.1)
|
17
17
|
ast (2.4.0)
|
18
18
|
byebug (9.1.0)
|
19
|
-
cnccs (0.1.
|
19
|
+
cnccs (0.1.2)
|
20
20
|
coderay (1.1.2)
|
21
21
|
diff-lcs (1.3)
|
22
22
|
docile (1.3.1)
|
@@ -24,8 +24,10 @@ GEM
|
|
24
24
|
nokogiri (>= 1.4.3)
|
25
25
|
ffi (1.9.25)
|
26
26
|
formatador (0.2.5)
|
27
|
-
|
27
|
+
gb-agencies (0.0.3)
|
28
|
+
gbbib (0.2.2)
|
28
29
|
cnccs (~> 0.1.1)
|
30
|
+
gb-agencies (~> 0.0.1)
|
29
31
|
iso-bib-item (~> 0.2)
|
30
32
|
guard (2.14.2)
|
31
33
|
formatador (>= 0.2.4)
|
@@ -42,15 +44,13 @@ GEM
|
|
42
44
|
guard-compat (~> 1.1)
|
43
45
|
rspec (>= 2.99.0, < 4.0)
|
44
46
|
httpclient (2.8.3)
|
45
|
-
|
46
|
-
nokogiri
|
47
|
-
iso-bib-item (0.2.2)
|
47
|
+
iso-bib-item (0.2.3)
|
48
48
|
isoics (~> 0.1.6)
|
49
49
|
nokogiri (~> 1.8.4)
|
50
50
|
ruby_deep_clone (~> 0.8.0)
|
51
|
-
isobib (0.2.
|
51
|
+
isobib (0.2.1)
|
52
52
|
algoliasearch
|
53
|
-
iso-bib-item (~> 0.2.
|
53
|
+
iso-bib-item (~> 0.2.3)
|
54
54
|
isoics (0.1.6)
|
55
55
|
jaro_winkler (1.5.1)
|
56
56
|
json (2.1.0)
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
rb-fsevent (0.10.3)
|
83
83
|
rb-inotify (0.9.10)
|
84
84
|
ffi (>= 0.5.0, < 2)
|
85
|
-
rfcbib (0.2.
|
85
|
+
rfcbib (0.2.2)
|
86
86
|
iso-bib-item (~> 0.2.0)
|
87
87
|
rspec (3.7.0)
|
88
88
|
rspec-core (~> 3.7.0)
|
@@ -97,7 +97,7 @@ GEM
|
|
97
97
|
diff-lcs (>= 1.2.0, < 2.0)
|
98
98
|
rspec-support (~> 3.7.0)
|
99
99
|
rspec-support (3.7.1)
|
100
|
-
rubocop (0.58.
|
100
|
+
rubocop (0.58.2)
|
101
101
|
jaro_winkler (~> 1.5.1)
|
102
102
|
parallel (~> 1.10)
|
103
103
|
parser (>= 2.5, != 2.5.1.1)
|
data/lib/relaton/db.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "pstore"
|
2
|
+
require "iso_bib_item"
|
2
3
|
require_relative "registry"
|
3
4
|
|
4
5
|
module Relaton
|
@@ -11,7 +12,7 @@ module Relaton
|
|
11
12
|
# @param local_cache [String] filename of local DB
|
12
13
|
def initialize(global_cache, local_cache)
|
13
14
|
@db = open_cache_biblio(global_cache)
|
14
|
-
@local_db = open_cache_biblio(local_cache)
|
15
|
+
@local_db = open_cache_biblio(local_cache, global: false)
|
15
16
|
@db_name = global_cache
|
16
17
|
@local_db_name = local_cache
|
17
18
|
register_gems
|
@@ -66,17 +67,13 @@ module Relaton
|
|
66
67
|
@db.transaction do
|
67
68
|
Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
68
69
|
xml.documents do
|
69
|
-
@db.roots.
|
70
|
+
@db.roots.reject { |key| key == :version }.
|
71
|
+
each { |key| @db[key]&.fetch("bib")&.to_xml(xml, {}) }
|
70
72
|
end
|
71
73
|
end.to_xml
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
|
-
# def save
|
76
|
-
# save_cache_biblio(@db, @db_name)
|
77
|
-
# save_cache_biblio(@local_db, @local_db_name)
|
78
|
-
# end
|
79
|
-
|
80
77
|
private
|
81
78
|
|
82
79
|
def standard_class(code)
|
@@ -144,15 +141,37 @@ module Relaton
|
|
144
141
|
end
|
145
142
|
|
146
143
|
# @param filename [String] DB filename
|
147
|
-
# @
|
148
|
-
|
144
|
+
# @param global [TrueClass, FalseClass]
|
145
|
+
# @return [PStore]
|
146
|
+
def open_cache_biblio(filename, global: true)
|
149
147
|
return nil if filename.nil?
|
150
|
-
PStore.new filename
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
148
|
+
db = PStore.new filename
|
149
|
+
if File.exist? filename
|
150
|
+
if global
|
151
|
+
unless check_cache_version(db)
|
152
|
+
File.delete filename
|
153
|
+
warn "Global cache version is obsolete and cleared."
|
154
|
+
end
|
155
|
+
set_cache_version db
|
156
|
+
elsif check_cache_version(db) then db
|
157
|
+
else
|
158
|
+
warn "Local cache version is obsolete."
|
159
|
+
nil
|
160
|
+
end
|
161
|
+
else
|
162
|
+
set_cache_version db
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def check_cache_version(cache_db)
|
167
|
+
cache_db.transaction { cache_db[:version] == VERSION }
|
168
|
+
end
|
169
|
+
|
170
|
+
def set_cache_version(cache_db)
|
171
|
+
unless File.exist? cache_db.path
|
172
|
+
cache_db.transaction { cache_db[:version] = VERSION }
|
173
|
+
end
|
174
|
+
cache_db
|
156
175
|
end
|
157
176
|
|
158
177
|
# @param enstry [String] entry in XML format
|
data/lib/relaton/version.rb
CHANGED
data/relaton.gemspec
CHANGED
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_dependency "algoliasearch"
|
31
31
|
spec.add_dependency "gbbib", "~> 0.2.1"
|
32
|
-
spec.add_dependency "iev", "~> 0.1.0"
|
33
32
|
spec.add_dependency "isobib", "~> 0.2.0"
|
34
|
-
spec.add_dependency "rfcbib", "~> 0.2.
|
33
|
+
spec.add_dependency "rfcbib", "~> 0.2.2"
|
34
|
+
spec.add_dependency 'iso-bib-item', '~> 0.2.3'
|
35
35
|
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.15"
|
37
37
|
spec.add_development_dependency "byebug", "~> 9.1"
|
@@ -1,27 +1,28 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe Relaton::Db do
|
4
|
-
let!(:db) { Relaton::Db.new("testcache", "testcache2") }
|
4
|
+
# let!(:db) { Relaton::Db.new("testcache", "testcache2") }
|
5
5
|
|
6
6
|
before :each do
|
7
7
|
system "rm testcache testcache2"
|
8
|
+
@db = Relaton::Db.new "testcache", "testcache2"
|
8
9
|
end
|
9
10
|
|
10
11
|
it "rejects an illegal reference prefix" do
|
11
|
-
expect { db.fetch("XYZ XYZ", nil, {}) }.to output(/does not have a recognised prefix/).to_stderr
|
12
|
+
expect { @db.fetch("XYZ XYZ", nil, {}) }.to output(/does not have a recognised prefix/).to_stderr
|
12
13
|
testcache = PStore.new "testcache"
|
13
14
|
testcache.transaction do
|
14
|
-
expect(testcache.roots.size).to eq
|
15
|
+
expect(testcache.roots.size).to eq 1
|
15
16
|
end
|
16
17
|
testcache = PStore.new "testcache2"
|
17
18
|
testcache.transaction do
|
18
|
-
expect(testcache.roots.size).to eq
|
19
|
+
expect(testcache.roots.size).to eq 1
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
it "gets an ISO reference and caches it" do
|
23
24
|
stub_bib Isobib::IsoBibliography
|
24
|
-
bib = db.fetch("ISO 19115-1", nil, {})
|
25
|
+
bib = @db.fetch("ISO 19115-1", nil, {})
|
25
26
|
expect(bib).to be_instance_of IsoBibItem::IsoBibliographicItem
|
26
27
|
expect(bib.to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
|
27
28
|
expect(File.exist?("testcache")).to be true
|
@@ -38,7 +39,7 @@ RSpec.describe Relaton::Db do
|
|
38
39
|
|
39
40
|
it "deals with a non-existant ISO reference" do
|
40
41
|
stub_bib Isobib::IsoBibliography
|
41
|
-
bib = db.fetch("ISO 111111119115-1", nil, {})
|
42
|
+
bib = @db.fetch("ISO 111111119115-1", nil, {})
|
42
43
|
expect(bib).to be_nil
|
43
44
|
expect(File.exist?("testcache")).to be true
|
44
45
|
expect(File.exist?("testcache2")).to be true
|
@@ -56,22 +57,22 @@ RSpec.describe Relaton::Db do
|
|
56
57
|
|
57
58
|
it "list all elements as a serialization" do
|
58
59
|
stub_bib Isobib::IsoBibliography, 2
|
59
|
-
db.fetch "ISO 19115-1", nil, {}
|
60
|
-
db.fetch "ISO 19115-2", nil, {}
|
60
|
+
@db.fetch "ISO 19115-1", nil, {}
|
61
|
+
@db.fetch "ISO 19115-2", nil, {}
|
61
62
|
file = "spec/support/list_entries.xml"
|
62
|
-
File.write file, db.to_xml unless File.exist? file
|
63
|
-
expect(db.to_xml).to eq File.read file
|
63
|
+
File.write file, @db.to_xml unless File.exist? file
|
64
|
+
expect(@db.to_xml).to eq File.read file
|
64
65
|
end
|
65
66
|
|
66
67
|
it "save/load entry" do
|
67
|
-
db.save_entry "test key", value: "test value"
|
68
|
-
expect(db.load_entry("test key")[:value]).to eq "test value"
|
69
|
-
expect(db.load_entry("not existed key")).to be_nil
|
68
|
+
@db.save_entry "test key", value: "test value"
|
69
|
+
expect(@db.load_entry("test key")[:value]).to eq "test value"
|
70
|
+
expect(@db.load_entry("not existed key")).to be_nil
|
70
71
|
end
|
71
72
|
|
72
73
|
it "get GB reference and cache it" do
|
73
74
|
stub_bib Gbbib::GbBibliography
|
74
|
-
bib = db.fetch "GB Standard GB/T 20223", "2006", {}
|
75
|
+
bib = @db.fetch "GB Standard GB/T 20223", "2006", {}
|
75
76
|
expect(bib).to be_instance_of Gbbib::GbBibliographicItem
|
76
77
|
expect(bib.to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
|
77
78
|
expect(File.exist?("testcache")).to be true
|
@@ -85,10 +86,10 @@ RSpec.describe Relaton::Db do
|
|
85
86
|
expect(testcache["GB Standard GB/T 20223:2006"]["bib"].to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
|
86
87
|
end
|
87
88
|
end
|
88
|
-
|
89
|
+
|
89
90
|
it "get RFC reference and cache it" do
|
90
91
|
stub_bib RfcBib::RfcBibliography
|
91
|
-
bib = db.fetch "RFC 8341", nil, {}
|
92
|
+
bib = @db.fetch "RFC 8341", nil, {}
|
92
93
|
expect(bib).to be_instance_of IsoBibItem::BibliographicItem
|
93
94
|
expect(bib.to_xml).to include "<bibitem id=\"RFC8341\">"
|
94
95
|
expect(File.exist?("testcache")).to be true
|
@@ -103,6 +104,20 @@ RSpec.describe Relaton::Db do
|
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
107
|
+
it "shoul clear global cache if version is changed" do
|
108
|
+
@db.save_entry "test_key", value: "test_value"
|
109
|
+
expect(File.exist?("testcache")).to be_truthy
|
110
|
+
expect(File.exist?("testcache2")).to be_truthy
|
111
|
+
stub_const "Relaton::VERSION", "new_version"
|
112
|
+
db = Relaton::Db.new "testcache", "testcache2"
|
113
|
+
testcache = db.instance_variable_get :@db
|
114
|
+
testcache.transaction do
|
115
|
+
expect(testcache.root?("test_key")).to be_falsey
|
116
|
+
end
|
117
|
+
testcache = db.instance_variable_get :@local_db
|
118
|
+
expect(testcache).to be_nil
|
119
|
+
end
|
120
|
+
|
106
121
|
private
|
107
122
|
|
108
123
|
# @param count [Integer] number of stubbing
|
Binary file
|
data/spec/support/iso_19115_1
CHANGED
Binary file
|
data/spec/support/iso_19115_2
CHANGED
Binary file
|
data/spec/support/rfc_8341
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: algoliasearch
|
@@ -39,47 +39,47 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: isobib
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rfcbib
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.2.
|
61
|
+
version: 0.2.2
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.2.
|
68
|
+
version: 0.2.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: iso-bib-item
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.2.
|
75
|
+
version: 0.2.3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.2.
|
82
|
+
version: 0.2.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|