relaton-index 0.2.12 → 0.2.14
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/lib/relaton/index/file_io.rb +24 -11
- data/lib/relaton/index/type.rb +14 -5
- data/lib/relaton/index/util.rb +18 -0
- data/lib/relaton/index/version.rb +1 -1
- data/lib/relaton/index.rb +3 -0
- data/relaton-index.gemspec +2 -0
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 074e4a9ad24460b1c4ae2b34bfbfe37e0674e204517d5137665b47ade1296295
|
4
|
+
data.tar.gz: 6b8df9730b13c94331942d2ed21f7ea27673d47e5e6fe4d9d4099e919a17de47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d014942345f4a0b208390fd2e1404c630acdc6c7112175883850a8a1118750565be104625fe1b0c470e92c55ac3ae1357a1b487f131cc2d515ed14b959e38641
|
7
|
+
data.tar.gz: 0cde39c9290fb2c7267aa8c5f9d61433eef2bdbbf5e17829d45921bada82feedba109532b2d08a28b117d1b0177acba54335b27d82e4792de4d205c6cf577693
|
@@ -6,7 +6,7 @@ module Relaton
|
|
6
6
|
# In index mode url should be nil.
|
7
7
|
#
|
8
8
|
class FileIO
|
9
|
-
attr_reader :url
|
9
|
+
attr_reader :url, :pubid_class
|
10
10
|
|
11
11
|
#
|
12
12
|
# Initialize FileIO
|
@@ -17,12 +17,14 @@ module Relaton
|
|
17
17
|
# and save it to the storage (if not exists, or older than 24 hours)
|
18
18
|
# if true then the index is read from the storage (used to remove index file)
|
19
19
|
# if nil then the fiename is used to read and write file (used to create indes in GH actions)
|
20
|
+
# @param [Pubid::Core::Identifier::Base] pubid class for deserialization
|
20
21
|
#
|
21
|
-
def initialize(dir, url, filename, id_keys)
|
22
|
+
def initialize(dir, url, filename, id_keys, pubid_class = nil)
|
22
23
|
@dir = dir
|
23
24
|
@url = url
|
24
25
|
@filename = filename
|
25
26
|
@id_keys = id_keys || []
|
27
|
+
@pubid_class = pubid_class
|
26
28
|
end
|
27
29
|
|
28
30
|
#
|
@@ -105,23 +107,33 @@ module Relaton
|
|
105
107
|
return unless yaml
|
106
108
|
|
107
109
|
index = YAML.safe_load yaml, permitted_classes: [Symbol]
|
108
|
-
return index if check_format index
|
110
|
+
return deserialize_pubid(index) if check_format index
|
109
111
|
|
110
112
|
warn_local_index_error "Wrong structure of the"
|
111
113
|
rescue Psych::SyntaxError
|
112
114
|
warn_local_index_error "YAML parsing error when reading"
|
113
115
|
end
|
114
116
|
|
117
|
+
def deserialize_pubid(index)
|
118
|
+
return index unless @pubid_class
|
119
|
+
|
120
|
+
index.map { |r| { id: @pubid_class.create(**r[:id]), file: r[:file] } }
|
121
|
+
end
|
122
|
+
|
115
123
|
def warn_local_index_error(reason)
|
116
|
-
|
124
|
+
Util.info "#{reason} file `#{file}`", progname
|
117
125
|
if url.is_a? String
|
118
|
-
|
126
|
+
Util.info "Considering `#{file}` file corrupt, re-downloading from `#{url}`", progname
|
119
127
|
else
|
120
|
-
|
128
|
+
Util.info "Considering `#{file}` file corrupt, removing it.", progname
|
121
129
|
remove
|
122
130
|
end
|
123
131
|
end
|
124
132
|
|
133
|
+
def progname
|
134
|
+
@progname ||= "relaton-#{@dir}"
|
135
|
+
end
|
136
|
+
|
125
137
|
#
|
126
138
|
# Fetch index from external repository and save it to storage
|
127
139
|
#
|
@@ -134,7 +146,7 @@ module Relaton
|
|
134
146
|
yaml = entry.get_input_stream.read
|
135
147
|
index = YAML.safe_load(yaml, permitted_classes: [Symbol])
|
136
148
|
save index
|
137
|
-
|
149
|
+
Util.info "Downloaded index from `#{url}`", progname
|
138
150
|
return index if check_format index
|
139
151
|
|
140
152
|
warn_remote_index_error "Wrong structure of"
|
@@ -143,9 +155,9 @@ module Relaton
|
|
143
155
|
end
|
144
156
|
|
145
157
|
def warn_remote_index_error(reason)
|
146
|
-
|
147
|
-
"
|
148
|
-
"
|
158
|
+
Util.info "#{reason} newly downloaded file `#{file}` at `#{url}`, " \
|
159
|
+
"the remote index seems to be invalid. Please report this " \
|
160
|
+
"issue at https://github.com/relaton/relaton-cli.", progname
|
149
161
|
end
|
150
162
|
|
151
163
|
#
|
@@ -156,7 +168,8 @@ module Relaton
|
|
156
168
|
# @return [void]
|
157
169
|
#
|
158
170
|
def save(index)
|
159
|
-
Index.config.storage.write file,
|
171
|
+
Index.config.storage.write file,
|
172
|
+
index.map { |item| item.transform_values { |value| value.is_a?(Pubid::Core::Identifier::Base) ? value.to_h : value } }.to_yaml
|
160
173
|
end
|
161
174
|
|
162
175
|
#
|
data/lib/relaton/index/type.rb
CHANGED
@@ -10,11 +10,12 @@ module Relaton
|
|
10
10
|
# @param [String, Symbol] type type of index (ISO, IEC, etc.)
|
11
11
|
# @param [String, nil] url external URL to index, used to fetch index for searching files
|
12
12
|
# @param [String, nil] file output file name
|
13
|
+
# @param [Pubid::Core::Identifier::Base] pubid class for deserialization
|
13
14
|
#
|
14
|
-
def initialize(type, url = nil, file = nil, id_keys = nil)
|
15
|
+
def initialize(type, url = nil, file = nil, id_keys = nil, pubid_class = nil)
|
15
16
|
@file = file
|
16
17
|
filename = file || Index.config.filename
|
17
|
-
@file_io = FileIO.new type.to_s.downcase, url, filename, id_keys
|
18
|
+
@file_io = FileIO.new type.to_s.downcase, url, filename, id_keys, pubid_class
|
18
19
|
end
|
19
20
|
|
20
21
|
def index
|
@@ -38,7 +39,7 @@ module Relaton
|
|
38
39
|
#
|
39
40
|
# Add or update index item
|
40
41
|
#
|
41
|
-
# @param [
|
42
|
+
# @param [Pubid::Core::Identifier::Base] id document ID
|
42
43
|
# @param [String] file file name of the document
|
43
44
|
#
|
44
45
|
# @return [void]
|
@@ -55,13 +56,21 @@ module Relaton
|
|
55
56
|
#
|
56
57
|
# Search index for a given ID
|
57
58
|
#
|
58
|
-
# @param [
|
59
|
+
# @param [String, Pubid::Core::Identifier::Base] id ID to search for
|
59
60
|
#
|
60
61
|
# @return [Array<Hash>] search results
|
61
62
|
#
|
62
63
|
def search(id = nil)
|
63
64
|
index.select do |i|
|
64
|
-
block_given?
|
65
|
+
if block_given?
|
66
|
+
yield(i)
|
67
|
+
else
|
68
|
+
if i[:id].is_a?(String)
|
69
|
+
id.is_a?(String) ? i[:id].include?(id) : i[:id].include?(id.to_s)
|
70
|
+
else
|
71
|
+
id.is_a?(String) ? i[:id].to_s.include?(id) : i[:id] == id
|
72
|
+
end
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Index
|
3
|
+
module Util
|
4
|
+
extend self
|
5
|
+
|
6
|
+
PROGNAME = "relaton-index".freeze
|
7
|
+
|
8
|
+
def method_missing(method_name, msg = nil, prog = nil, **opts, &block)
|
9
|
+
prog ||= self::PROGNAME
|
10
|
+
Relaton.logger_pool.send method_name, msg, prog, **opts, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def respond_to_missing?(method_name, include_private = false)
|
14
|
+
Relaton.logger_pool.respond_to?(method_name) || super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/relaton/index.rb
CHANGED
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
require "yaml"
|
4
4
|
require "zip"
|
5
|
+
require "relaton/logger"
|
6
|
+
require "pubid-core"
|
5
7
|
|
6
8
|
require_relative "index/version"
|
7
9
|
require_relative "index/file_storage"
|
8
10
|
require_relative "index/config"
|
11
|
+
require_relative "index/util"
|
9
12
|
require_relative "index/pool"
|
10
13
|
require_relative "index/type"
|
11
14
|
require_relative "index/file_io"
|
data/relaton-index.gemspec
CHANGED
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
+
spec.add_dependency "pubid-core", "~> 1.12.9"
|
34
|
+
spec.add_dependency "relaton-logger", "~> 0.2.0"
|
33
35
|
spec.add_dependency "rubyzip", "~> 2.3.0"
|
34
36
|
|
35
37
|
# For more information and examples about making a new gem, check out our
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-index
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pubid-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.12.9
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.12.9
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: relaton-logger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rubyzip
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +71,7 @@ files:
|
|
43
71
|
- lib/relaton/index/file_storage.rb
|
44
72
|
- lib/relaton/index/pool.rb
|
45
73
|
- lib/relaton/index/type.rb
|
74
|
+
- lib/relaton/index/util.rb
|
46
75
|
- lib/relaton/index/version.rb
|
47
76
|
- relaton-index.gemspec
|
48
77
|
- sig/relaton/index.rbs
|
@@ -67,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
96
|
- !ruby/object:Gem::Version
|
68
97
|
version: '0'
|
69
98
|
requirements: []
|
70
|
-
rubygems_version: 3.3.
|
99
|
+
rubygems_version: 3.3.27
|
71
100
|
signing_key:
|
72
101
|
specification_version: 4
|
73
102
|
summary: Relaton Index is a library for indexing Relaton files.
|