relaton-index 0.1.6 → 0.1.8

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: d43fbc7d91123a99bde7050b74ee42d38408a610d6aab858a3e9a032b41e2a26
4
- data.tar.gz: d3655957e051b6b1d3f0d2d7a223fab43e63a0186fa946092446611804c1fc23
3
+ metadata.gz: 60a1a3374a5ce4bf3ed866e1f16c1bfc23e60e540f01689e70f6de64ddd77000
4
+ data.tar.gz: 2ad750089311e884d7fbe3de14f45769e578a4bd4de76a90ca1710a4733396e3
5
5
  SHA512:
6
- metadata.gz: 4d70ce12c06d309f611949aa6c138e03093be574830cf0b13389f8d41849cfae16a7b150726d1a1d8ac1f3eb263e657b32143a2d5f2102412a2f106af6d80649
7
- data.tar.gz: 20f183f6b0c279825bceddc016fb87449ce475983d08029c6152c7552528df4fe385c7d6ca0818add7c2cc64219651636be995009d7a5de3cbb62dbfa243f252
6
+ metadata.gz: e62a664b3974dcf33b11b04601514aefe89d7891a750d76622097fb66a836fab28808c8f5844e026c5d1578997aa7e8057b2cf34222a5a207f24e2c55ba5f22f
7
+ data.tar.gz: 4c40187df923f53aa096aa717486f3f82a5cacb0411b1de9886dbbe533f8d7cff6e968aa96c95dc24675a8d192e098839c5ccd67faeaaa2e497570e21b77c464
data/README.adoc CHANGED
@@ -83,11 +83,22 @@ end
83
83
 
84
84
  === Remove all index records
85
85
 
86
+ This method removes all records from the index object. The index file is not removed.
87
+
86
88
  [source,ruby]
87
89
  ----
88
90
  index.remove_all
89
91
  ----
90
92
 
93
+ === Remove index file
94
+
95
+ This method removes the index file. The index object is cleared and can be used for indexing or loading a file from the specified URL.
96
+
97
+ [source,ruby]
98
+ ----
99
+ index.remove
100
+ ----
101
+
91
102
  === Configuration
92
103
 
93
104
  The gem can be configured by using the `Relaton::Index.config` method. The following settings are available:
@@ -78,13 +78,22 @@ module Relaton
78
78
  #
79
79
  # Save index to storage
80
80
  #
81
- # @param [Array<Hash>] index <description>
81
+ # @param [Array<Hash>] index index to save
82
82
  #
83
83
  # @return [void]
84
84
  #
85
85
  def save(index)
86
86
  Index.config.storage.write @file, index.to_yaml
87
87
  end
88
+
89
+ #
90
+ # Remove index file from storage
91
+ #
92
+ # @return [void]
93
+ #
94
+ def remove
95
+ Index.config.storage.remove @file
96
+ end
88
97
  end
89
98
  end
90
99
  end
@@ -42,6 +42,19 @@ module Relaton
42
42
  File.write file, data, encoding: "UTF-8"
43
43
  end
44
44
 
45
+ #
46
+ # Remove file
47
+ #
48
+ # @param [String] file file path
49
+ #
50
+ # @return [void]
51
+ #
52
+ def remove(file)
53
+ return unless File.exist? file
54
+
55
+ File.delete file
56
+ end
57
+
45
58
  extend self
46
59
  end
47
60
  end
@@ -15,7 +15,10 @@ module Relaton
15
15
  @file = file
16
16
  filename = file || Index.config.filename
17
17
  @file_io = FileIO.new type.to_s.downcase, url, filename
18
- @index = @file_io.read
18
+ end
19
+
20
+ def index
21
+ @index ||= @file_io.read
19
22
  end
20
23
 
21
24
  #
@@ -41,11 +44,11 @@ module Relaton
41
44
  # @return [void]
42
45
  #
43
46
  def add_or_update(id, file)
44
- item = @index.find { |i| i[:id] == id }
47
+ item = index.find { |i| i[:id] == id }
45
48
  if item
46
49
  item[:file] = file
47
50
  else
48
- @index << { id: id, file: file }
51
+ index << { id: id, file: file }
49
52
  end
50
53
  end
51
54
 
@@ -57,7 +60,7 @@ module Relaton
57
60
  # @return [Array<Hash>] search results
58
61
  #
59
62
  def search(id = nil)
60
- @index.select do |i|
63
+ index.select do |i|
61
64
  block_given? ? yield(i) : i[:id].include?(id)
62
65
  end
63
66
  end
@@ -71,6 +74,16 @@ module Relaton
71
74
  @file_io.save @index
72
75
  end
73
76
 
77
+ #
78
+ # Remove index file from storage and clear index
79
+ #
80
+ # @return [void]
81
+ #
82
+ def remove
83
+ @file_io.remove
84
+ @index = nil
85
+ end
86
+
74
87
  #
75
88
  # Remove all index items
76
89
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Index
5
- VERSION = "0.1.6"
5
+ VERSION = "0.1.8"
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.6
4
+ version: 0.1.8
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-04-14 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.1.6
70
+ rubygems_version: 3.3.26
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Relaton Index is a library for indexing Relaton files.