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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e768443355f1c5764d5b5061f65c513485446f6df9ebce67b5b5f58a4ac30b20
4
- data.tar.gz: 9062103447a89fd2e7484c448ac80315906a2602fba363e142c47f0d5ecc592d
3
+ metadata.gz: 0032a2287829a2a4beb5d2561a99f716a04d6d6ea5a2d99da93fed6dfb187eff
4
+ data.tar.gz: 3af5842649ea9db629117699d44941742104aec93d35b87378d729b8d020ec98
5
5
  SHA512:
6
- metadata.gz: 4889cfefdf5cadbaddd47f83e31a870829a9b144dddb346b8cf6f72d55fac68d6a75c1d7f180e315720f90eeb70801fd2a987920055c2d4334537955bd544678
7
- data.tar.gz: 49c5b9a1d34de8335b815e7e56070d2fa9bfdaa2a9a931f53c93ac28bff6e3da03f307f57c5faf8155bf0c01ef7ee5a61956d0605cc7d372247f184da0b0c3a6
6
+ metadata.gz: 8048e13e77c8aa8be78444b4c3e18aa955636434fb7f15f205f37b039f4c94122515f4481b3a4881923bb37661f8de968e2c80b8bf8fa2d9a101cf19ab7f9341
7
+ data.tar.gz: 5d1aeda6151c09f0c9249aa6b6d2800f54749b5a1a5050a21e1d56bb1562e4935c5b0755b92be070164acb108db7c7db488a03e0ca4d99c3493adc1b3879f55d
@@ -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
- num_of_entries = entries.size
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
- # case insensitive, print line number, recursive search, work as egrep
353
- "grep" => ["-i", "-n", "-R", "-E"],
354
- # case insensitive, print line number, recursive search
355
- "egrep" => ["-i", "-n", "-R"],
356
- # case insensitive, print line number, recursive search, work as gegrep
357
- "ggrep" => ["-i", "-n", "-R", "-E"],
358
- # case insensitive, print line number, recursive search
359
- "gegrep" => ["-i", "-n", "-R"],
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
  }
@@ -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'
@@ -1,3 +1,3 @@
1
1
  module Textrepo
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
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.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-10 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler