relaton-index 0.1.1 → 0.1.3

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: c687782518f5a65ec1d2817f0465ad259512fd036c245405c51d33791c9283a8
4
- data.tar.gz: 0ad89006b9935eabfa69493c230337be7b0b4f698c9e2cc8fb2caef3e11b5862
3
+ metadata.gz: ae7a2387f5e09bff4b3d07563d7e6b3daec43720e7af59d5387f62c41d3892e4
4
+ data.tar.gz: 8cd557981092f4f37c7d5a318eb6655472895f1a383044af469615e4e99430c0
5
5
  SHA512:
6
- metadata.gz: 18479264d80c4139e0a819a3a49c8c06b7d0f864e8b01098eaa9535a593c2cb3f7117c025ac6fd978b54350aa390685d16b380e05ac5778ce4d4d2e0effe63a4
7
- data.tar.gz: 84cdc050c23d872de768672274189ad453708ecd961f8cdbac15e51e59aec64d4a6c9f9f7760b507ea602b7dc2dba04874a01a83d2be911d69361a33e300013b
6
+ metadata.gz: aebc8bc1def475961474cb000a79d02d8341f1f9687d93d93559f0126cbf7d091a88fcdfdb0308f181bda3bfc9539cfd876f159936f488cd6117fc21baaf1cac
7
+ data.tar.gz: 35ad2ae0c5c84328860147a1c5422548bf99437496085d1d0f29f3b2515344e8dca01bad75f40a6f21a84838576763c811d9f873b06afde1ff90e73623f4b4bc
data/README.adoc CHANGED
@@ -28,7 +28,7 @@ The aim of this gem is to be used by Relaton libraries in two ways:
28
28
 
29
29
  === Indexing
30
30
 
31
- In this case, the Relaton library should create an index object and add documents' files to it. The index object should be saved to the `index.yaml` file in the root of the repository.
31
+ In this case, the Relaton library creates an index object and adds documents' files to it. By default, the index object is saved to the `index.yaml` file in the root of the repository. The filename can be changed using the `filename` setting
32
32
 
33
33
  [source,ruby]
34
34
  ----
@@ -52,7 +52,7 @@ In this case, the Relaton library should create an index object and search for a
52
52
  ----
53
53
  require 'relaton/index'
54
54
 
55
- # Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index file is saved to the `/[HOME]/.relaton/[TYPE]/index.yaml` file.
55
+ # Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index file is saved to the `/[HOME]/.relaton/iho/index.yaml` file.
56
56
  index = Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/relaton/relaton-data-iho/master/index.zip"
57
57
 
58
58
 
@@ -71,6 +71,23 @@ end
71
71
  Relaton::Index.close :IHO
72
72
  ----
73
73
 
74
+ === Configuration
75
+
76
+ The gem can be configured by using the `Relaton::Index.config` method. The following settings are available:
77
+
78
+ - `filename` - the name of the index file. By default, it is `index.yaml`.
79
+ - `storage` - the storage class or module. By default, it is `FileStorage` module. It can be any class or module that implements the `ctime`, `read`, and `write` class methods.
80
+ - `storage_dir` - the directory where the `.relaton/[TYPE]` folder is created. By default, it's a user's home dir. This setting works only when the gem is used for searching. When indexing, the index is always saved in a current folder.
81
+
82
+ [source,ruby]
83
+ ----
84
+ Relaton::Index.config do |config|
85
+ config.filename = "index-new.yaml"
86
+ config.storage = S3Storage
87
+ config.storage_dir = "/"
88
+ end
89
+ ----
90
+
74
91
  == Development
75
92
 
76
93
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -4,7 +4,7 @@ module Relaton
4
4
  # Configuration class for Relaton::Index
5
5
  #
6
6
  class Config
7
- attr_reader :storage, :storage_dir
7
+ attr_reader :storage, :storage_dir, :filename
8
8
 
9
9
  #
10
10
  # Set default values
@@ -12,6 +12,7 @@ module Relaton
12
12
  def initialize
13
13
  @storage = FileStorage
14
14
  @storage_dir = Dir.home
15
+ @filename = "index.yaml"
15
16
  end
16
17
 
17
18
  #
@@ -35,6 +36,17 @@ module Relaton
35
36
  def storage_dir=(dir)
36
37
  @storage_dir = dir
37
38
  end
39
+
40
+ #
41
+ # Set filename
42
+ #
43
+ # @param [String] filename filename
44
+ #
45
+ # @return [void]
46
+ #
47
+ def filename=(filename)
48
+ @filename = filename
49
+ end
38
50
  end
39
51
  end
40
52
  end
@@ -10,8 +10,9 @@ module Relaton
10
10
  # Initialize FileIO
11
11
  #
12
12
  # @param [String] dir local directory in ~/.relaton to store index
13
- # @param [String, nil] url git repository URL to fetch index from (if not exists, or older than 24 hours)
14
- # or nil if index is used to index files
13
+ # @param [String, nil] url git repository URL to fetch index from
14
+ # (if not exists, or older than 24 hours) or nil if index is used to
15
+ # index files
15
16
  #
16
17
  def initialize(dir, url)
17
18
  @dir = dir
@@ -25,10 +26,10 @@ module Relaton
25
26
  #
26
27
  def read
27
28
  if @url
28
- @file ||= File.join(Index.config.storage_dir, ".relaton", @dir, "index.yaml")
29
+ @file ||= File.join(Index.config.storage_dir, ".relaton", @dir, Index.config.filename)
29
30
  check_file || fetch_and_save
30
31
  else
31
- @file ||= "index.yaml"
32
+ @file ||= Index.config.filename
32
33
  read_file
33
34
  end
34
35
  end
@@ -66,7 +67,7 @@ module Relaton
66
67
  resp = URI(@url).open
67
68
  zip = Zip::InputStream.new resp
68
69
  entry = zip.get_next_entry
69
- index = YAML.safe_load(entry.get_input_stream.read, [Symbol])
70
+ index = YAML.safe_load(entry.get_input_stream.read, permitted_classes: [Symbol])
70
71
  save index
71
72
  index
72
73
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Index
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2023-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip