relaton-index 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94b98c8a3a2f93284d50aefe422e0fea795bf697c7f4cd4bce8fcf517ccd2f62
4
- data.tar.gz: 63dbd9440f0cf7dbb58a043bce06940d1ac50e4a43513ab148ce292177a37f22
3
+ metadata.gz: 60a1a3374a5ce4bf3ed866e1f16c1bfc23e60e540f01689e70f6de64ddd77000
4
+ data.tar.gz: 2ad750089311e884d7fbe3de14f45769e578a4bd4de76a90ca1710a4733396e3
5
5
  SHA512:
6
- metadata.gz: ae44baa7e0019a6de91cdecbc23c5c832425f84fd53f2f9262fd7d295a4df8bf3e95d96628326561023a90c1fd9a90cb2cee6cd0e542033d011ce5975a2f2354
7
- data.tar.gz: cef211d3dbf82b2105bfc3035a1f7d140ca41e9cd4a7a35559fd2709189dc36528a744d927ccf969cbc8827bb6405b3dda3659a273fda9794635ff4a11313e28
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.7"
5
+ VERSION = "0.1.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.