textrepo 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/textrepo/file_system_repository.rb +11 -22
- data/lib/textrepo/repository.rb +61 -0
- data/lib/textrepo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0032a2287829a2a4beb5d2561a99f716a04d6d6ea5a2d99da93fed6dfb187eff
|
4
|
+
data.tar.gz: 3af5842649ea9db629117699d44941742104aec93d35b87378d729b8d020ec98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8048e13e77c8aa8be78444b4c3e18aa955636434fb7f15f205f37b039f4c94122515f4481b3a4881923bb37661f8de968e2c80b8bf8fa2d9a101cf19ab7f9341
|
7
|
+
data.tar.gz: 5d1aeda6151c09f0c9249aa6b6d2800f54749b5a1a5050a21e1d56bb1562e4935c5b0755b92be070164acb108db7c7db488a03e0ca4d99c3493adc1b3879f55d
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
Nothing to record here.
|
9
9
|
|
10
|
+
## [0.5.6] - 2020-11-11
|
11
|
+
### Add
|
12
|
+
- Change `Repository` to enumerable.
|
13
|
+
- add `#each` method to `Repository`, then include `Enumerable`.
|
14
|
+
- Add "-H" option to some searcher default options.
|
15
|
+
|
10
16
|
## [0.5.5] - 2020-11-10
|
11
17
|
### Add
|
12
18
|
- Add more methods for `Timestamp` class.
|
@@ -317,20 +317,7 @@ module Textrepo
|
|
317
317
|
def invoke_searcher_for_entries(searcher, pattern, entries)
|
318
318
|
output = []
|
319
319
|
|
320
|
-
|
321
|
-
if num_of_entries == 1
|
322
|
-
# If the search taget is one file, the output needs special
|
323
|
-
# treatment.
|
324
|
-
file = abspath(entries[0])
|
325
|
-
o, s = Open3.capture2(searcher, *find_searcher_options(searcher),
|
326
|
-
pattern, file)
|
327
|
-
if s.success? && (! o.empty?)
|
328
|
-
output += o.lines.map { |line|
|
329
|
-
# add filename at the beginning of the search result line
|
330
|
-
[file, line.chomp].join(":")
|
331
|
-
}
|
332
|
-
end
|
333
|
-
elsif num_of_entries > LIMIT_OF_FILES
|
320
|
+
if entries.size > LIMIT_OF_FILES
|
334
321
|
output += invoke_searcher_for_entries(searcher, pattern, entries[0..(LIMIT_OF_FILES - 1)])
|
335
322
|
output += invoke_searcher_for_entries(searcher, pattern, entries[LIMIT_OF_FILES..-1])
|
336
323
|
else
|
@@ -349,14 +336,16 @@ module Textrepo
|
|
349
336
|
end
|
350
337
|
|
351
338
|
SEARCHER_OPTS = {
|
352
|
-
#
|
353
|
-
|
354
|
-
#
|
355
|
-
|
356
|
-
#
|
357
|
-
|
358
|
-
|
359
|
-
"
|
339
|
+
# grep option meaning:
|
340
|
+
# - "-i": case insensitive,
|
341
|
+
# - "-n": print line number,
|
342
|
+
# - "-H": print file name,
|
343
|
+
# - "-R": recursive search,
|
344
|
+
# - "-E": work as egrep
|
345
|
+
"grep" => ["-i", "-n", "-H", "-R", "-E"],
|
346
|
+
"egrep" => ["-i", "-n", "-H", "-R"],
|
347
|
+
"ggrep" => ["-i", "-n", "-H", "-R", "-E"],
|
348
|
+
"gegrep" => ["-i", "-n", "-H", "-R"],
|
360
349
|
# smart case, print line number, no color
|
361
350
|
"rg" => ["-S", "-n", "--no-heading", "--color", "never"],
|
362
351
|
}
|
data/lib/textrepo/repository.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Textrepo
|
2
2
|
class Repository
|
3
3
|
|
4
|
+
include Enumerable
|
5
|
+
|
4
6
|
##
|
5
7
|
# Repository type. It specifies which concrete repository class
|
6
8
|
# will instantiated. For example, the type `:file_system` specifies
|
@@ -125,6 +127,65 @@ module Textrepo
|
|
125
127
|
|
126
128
|
def search(pattern, stamp_pattern = nil); []; end
|
127
129
|
|
130
|
+
##
|
131
|
+
# Calls the given block once for each pair of timestamp and text
|
132
|
+
# in self, passing those pair as parameter. Returns the
|
133
|
+
# repository itself.
|
134
|
+
#
|
135
|
+
# If no block is given, an Enumerator is returned.
|
136
|
+
|
137
|
+
def each(&block)
|
138
|
+
if block.nil?
|
139
|
+
entries.lazy.map { |timestamp| pair(timestamp) }.to_enum(:each)
|
140
|
+
else
|
141
|
+
entries.each { |timestamp| yield pair(timestamp) }
|
142
|
+
self
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
alias each_pair each
|
147
|
+
|
148
|
+
##
|
149
|
+
# Calls the given block once for each timestamp in self, passing
|
150
|
+
# the timestamp as a parameter. Returns the repository itself.
|
151
|
+
#
|
152
|
+
# If no block is given, an Enumerator is returned.
|
153
|
+
|
154
|
+
def each_key(&block)
|
155
|
+
if block.nil?
|
156
|
+
entries.to_enum(:each)
|
157
|
+
else
|
158
|
+
entries.each(&block)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
alias each_timestamp each_key
|
163
|
+
|
164
|
+
##
|
165
|
+
# Calls the given block once for each timestamp in self, passing
|
166
|
+
# the text as a parameter. Returns the repository itself.
|
167
|
+
#
|
168
|
+
# If no block is given, an Enumerator is returned.
|
169
|
+
|
170
|
+
def each_value(&block)
|
171
|
+
if block.nil?
|
172
|
+
entries.lazy.map { |timestamp| read(timestamp) }.to_enum(:each)
|
173
|
+
else
|
174
|
+
entries.each { |timestamp| yield read(timestamp) }
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
alias each_text each_value
|
179
|
+
|
180
|
+
# :stopdoc:
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
def pair(timestamp)
|
185
|
+
[timestamp, read(timestamp)]
|
186
|
+
end
|
187
|
+
|
188
|
+
# :startdoc:
|
128
189
|
end
|
129
190
|
|
130
191
|
require_relative 'file_system_repository'
|
data/lib/textrepo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|