relaton-index 0.1.8 → 0.2.0

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: 60a1a3374a5ce4bf3ed866e1f16c1bfc23e60e540f01689e70f6de64ddd77000
4
- data.tar.gz: 2ad750089311e884d7fbe3de14f45769e578a4bd4de76a90ca1710a4733396e3
3
+ metadata.gz: 0eaf31518d3ecfb78041891165d24d8f0e9673d2aebcfa02608694ec9f562843
4
+ data.tar.gz: 206c0f5fcf0b5336ff186f35da3efc79fda86cf25c93f1c499dd525cccdd6128
5
5
  SHA512:
6
- metadata.gz: e62a664b3974dcf33b11b04601514aefe89d7891a750d76622097fb66a836fab28808c8f5844e026c5d1578997aa7e8057b2cf34222a5a207f24e2c55ba5f22f
7
- data.tar.gz: 4c40187df923f53aa096aa717486f3f82a5cacb0411b1de9886dbbe533f8d7cff6e968aa96c95dc24675a8d192e098839c5ccd67faeaaa2e497570e21b77c464
6
+ metadata.gz: 3426d0303d776d0c7ecaeb17bf957a20228858ae859f85aec02d52dc833d643ead02cd14c522d6fcecc72b9f920e2efbc3667f31c86e6dcd363ebc4ef9eae516
7
+ data.tar.gz: 0e8809f80cc34c92100a081917ce561ccaeb287e9002171f558d62e0c6148ac68a5b4b72f96e8720815f4d3be9390cda026fe39b08c3ba0895706c15a74e8865
data/README.adoc CHANGED
@@ -61,11 +61,11 @@ index.save
61
61
 
62
62
  === Searching
63
63
 
64
- In this case, the Relaton library should create an index object and search for a document by reference. The gem looks for the `.relaton/[TYPE]/index.yaml` file in the user's home directory. The `[TYPE]` is one of downcased ISO, IEC, IHO, etc. If the file is not found or is older than 24 hours then it will be downloaded from the URL specified in the `find_or_create` method.
64
+ In this case, the Relaton library should create an index object and search for a document by reference. The gem looks for the `.relaton/[TYPE]/index.yaml` file in the user's home directory. The `[TYPE]` is one of downcased ISO, IEC, IHO, etc. If the file is not found or is older than 24 hours then it will be downloaded from the URL specified in the `find_or_create` method. The URL can be specified as `true` if the index should not be fetched from the URL.
65
65
 
66
66
  [source,ruby]
67
67
  ----
68
- # 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 is saved as `index.yaml` file to the `/[HOME]/.relaton/iho/` folder.
68
+ # 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 is saved as `index.yaml` file to the `/[HOME]/.relaton/iho/` folder. If the URL is specified as `true`, the index won't be fetched from the URL.
69
69
  index = Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/relaton/relaton-data-iho/master/index.zip"
70
70
 
71
71
 
@@ -96,7 +96,7 @@ This method removes the index file. The index object is cleared and can be used
96
96
 
97
97
  [source,ruby]
98
98
  ----
99
- index.remove
99
+ index.remove_file
100
100
  ----
101
101
 
102
102
  === Configuration
@@ -12,7 +12,7 @@ module Relaton
12
12
  # Initialize FileIO
13
13
  #
14
14
  # @param [String] dir local directory in ~/.relaton to store index
15
- # @param [String, nil] url git repository URL to fetch index from
15
+ # @param [String, Boolean, nil] url git repository URL to fetch index from
16
16
  # (if not exists, or older than 24 hours) or nil if index is used to
17
17
  # index files
18
18
  #
@@ -23,27 +23,43 @@ module Relaton
23
23
  end
24
24
 
25
25
  #
26
- # Read index from storage or fetch from external repository
26
+ # If url is String, check if index file exists and is not older than 24
27
+ # hours. If not, fetch index from external repository and save it to
28
+ # storage.
29
+ # If url is true, remove index from storage.
30
+ # If url is nil, read index from file.
27
31
  #
28
32
  # @return [Array<Hash>] index
29
33
  #
30
34
  def read
31
- if url
32
- @file ||= File.join(Index.config.storage_dir, ".relaton", @dir, @filename)
35
+ case url
36
+ when String
33
37
  check_file || fetch_and_save
34
38
  else
35
- @file ||= @filename
36
39
  read_file
37
40
  end
38
41
  end
39
42
 
43
+ def file
44
+ @file ||= url ? path_to_local_file : @filename
45
+ end
46
+
47
+ #
48
+ # Create path to local file
49
+ #
50
+ # @return [<Type>] <description>
51
+ #
52
+ def path_to_local_file
53
+ File.join(Index.config.storage_dir, ".relaton", @dir, @filename)
54
+ end
55
+
40
56
  #
41
57
  # Check if index file exists and is not older than 24 hours
42
58
  #
43
59
  # @return [Array<Hash>, nil] index or nil
44
60
  #
45
61
  def check_file
46
- ctime = Index.config.storage.ctime(@file)
62
+ ctime = Index.config.storage.ctime(file)
47
63
  return unless ctime && ctime > Time.now - 86400
48
64
 
49
65
  read_file
@@ -55,7 +71,7 @@ module Relaton
55
71
  # @return [Array<Hash>] index
56
72
  #
57
73
  def read_file
58
- yaml = Index.config.storage.read(@file)
74
+ yaml = Index.config.storage.read(file)
59
75
  return [] unless yaml
60
76
 
61
77
  YAML.safe_load yaml, permitted_classes: [Symbol]
@@ -83,16 +99,17 @@ module Relaton
83
99
  # @return [void]
84
100
  #
85
101
  def save(index)
86
- Index.config.storage.write @file, index.to_yaml
102
+ Index.config.storage.write file, index.to_yaml
87
103
  end
88
104
 
89
105
  #
90
106
  # Remove index file from storage
91
107
  #
92
- # @return [void]
108
+ # @return [Array]
93
109
  #
94
110
  def remove
95
- Index.config.storage.remove @file
111
+ Index.config.storage.remove file
112
+ []
96
113
  end
97
114
  end
98
115
  end
@@ -79,7 +79,7 @@ module Relaton
79
79
  #
80
80
  # @return [void]
81
81
  #
82
- def remove
82
+ def remove_file
83
83
  @file_io.remove
84
84
  @index = nil
85
85
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Index
5
- VERSION = "0.1.8"
5
+ VERSION = "0.2.0"
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.8
4
+ version: 0.2.0
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-05-10 00:00:00.000000000 Z
11
+ date: 2023-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip