relaton-index 0.2.12 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e8920bb67f033d7164f4543a40ffc8588b6bbe4de64b6635b92379b77cfed2e
4
- data.tar.gz: c809a8e39de290734cd2a7eb5948c10f94b942f15b61f9485fea4d6b157bb474
3
+ metadata.gz: 5ce9d7205daf0975990050a9f2652f35d7fc9cd02a840f49cc268ee3114c0870
4
+ data.tar.gz: b0a56e175a3ca0ed09dea40d2b0d6cb1d6b7400f5cb61d67a86185f00d9309d6
5
5
  SHA512:
6
- metadata.gz: 558a2747f8cd219d018bb59472c09caf279d4e5f0e0637329872e7dfdd7e11eee70173f042f8b025df509b9eb23763357b6cfaae21606f4572b0f30a662fc84f
7
- data.tar.gz: '059d3c22c7248132aeb1c73e211af04154a0ec846f7c9c2d402b12bdd6f67fe5264b80a94a529993d0d26420dd5eaa5f4dcfbb7f9d637480d74d57ef120a4a68'
6
+ metadata.gz: 21cd6e533b27e00ee9b0604eb3a11112dba1c8f69db15996beede0b7ce763ae54ac30242e8a75118c6e525b4bde510bd7b68f347ccbdd180479d38b77f2c88c0
7
+ data.tar.gz: 2788d0c92aa0e4fe6540eb4fb5ae4b30917abb304f91b09add060efbcd81977427503c5e7ddc15c17afd1db9735a1abecdfe0a0b760de3d7b89d9e3a41476c59
@@ -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
- warn "[relaton-#{@dir}] #{reason} file #{file}"
124
+ Util.info "#{reason} file `#{file}`", progname
117
125
  if url.is_a? String
118
- warn "[relaton-#{@dir}] Considering #{file} file corrupt, re-downloading from #{url}"
126
+ Util.info "Considering `#{file}` file corrupt, re-downloading from `#{url}`", progname
119
127
  else
120
- warn "[relaton-#{@dir}] Considering #{file} file corrupt, removing it."
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
- warn "[relaton-#{@dir}] Downloaded index from #{url}"
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
- warn "[relaton-#{@dir}] #{reason} newly downloaded file " \
147
- "at #{file} #{url}, the remote index seems to be invalid." \
148
- "Please report this issue at https://github.com/relaton/relaton-cli."
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, index.to_yaml
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
  #
@@ -22,7 +22,7 @@ module Relaton
22
22
  if @pool[type.upcase.to_sym]&.actual?(**args)
23
23
  @pool[type.upcase.to_sym]
24
24
  else
25
- @pool[type.upcase.to_sym] = Type.new(type, args[:url], args[:file], args[:id_keys])
25
+ @pool[type.upcase.to_sym] = Type.new(type, args[:url], args[:file], args[:id_keys], args[:pubid_class])
26
26
  end
27
27
  end
28
28
 
@@ -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 [String] id document ID
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 [Comparable] id ID to search for
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? ? yield(i) : i[:id].include?(id)
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
 
@@ -71,7 +80,7 @@ module Relaton
71
80
  # @return [void]
72
81
  #
73
82
  def save
74
- @file_io.save @index
83
+ @file_io.save(@index || [])
75
84
  end
76
85
 
77
86
  #
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Index
5
- VERSION = "0.2.12"
5
+ VERSION = "0.2.15"
6
6
  end
7
7
  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"
@@ -16,17 +19,10 @@ module Relaton
16
19
 
17
20
  class << self
18
21
  #
19
- # Find or create index
22
+ # Proxy for Pool#type
20
23
  #
21
- # @param [String] type index type (ISO, IEC, etc.)
22
- # @param [String, nil] url external URL to index, used to fetch index for searching files
23
- # @param [String, nil] file output file name, default is config.filename
24
- # @param [Array<Symbol>, nil] id_keys keys to check if index is correct
25
- #
26
- # @return [Relaton::Index::Type] typed index
27
- #
28
- def find_or_create(type, url: nil, file: nil, id_keys: nil)
29
- pool.type(type, url: url, file: file, id_keys: id_keys)
24
+ def find_or_create(type, **args)
25
+ pool.type(type, **args)
30
26
  end
31
27
 
32
28
  def close(type)
@@ -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.12
4
+ version: 0.2.15
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-01-12 00:00:00.000000000 Z
11
+ date: 2024-08-08 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.26
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.