wgit 0.10.4 → 0.10.5

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: 13a092ae05f0338598d0cc26d85ed828a86d60240eb996bacdbd7511aaae25a2
4
- data.tar.gz: 3835b8aa3c06d49c1230dd42316c30315e39b0b33f0c433ff8df60eb6be2ecaa
3
+ metadata.gz: a359a5011cce717a84c0fa353cba658a4abcd11d2e8575da701b39eef35f641c
4
+ data.tar.gz: 730b2eee3c88d9cd99c1d9754744aa4bae71bc10019113e840f2914b3a7909e5
5
5
  SHA512:
6
- metadata.gz: 41a88d424925e3ba670104e69d027a5656c66616ab59bc85c62ec3359afd78230073e5a8f50697cbfc553b8dc9a012cf2ad2f2d857f7840fc668e0e43cdbfb33
7
- data.tar.gz: 17bd6ddaba4cb53bd5cff4f9b36d5930f4bf496ee588163d190e10274438844f1a5e764c08fc7f82dc6c5c6b2efebaa52dc624be134e38a7d9d3ff9b970d1430
6
+ metadata.gz: 4807d488cf03aa3dcf624249bd5169871bc17dd7e2de273cb841801147c040843912edc225a1f7346e427c022ecb2ce5360581323509221560ee99b31ea6a72b
7
+ data.tar.gz: ea3f1237116d05bbb24b2e85fdba1b6447821377a07ff5c5e6afea859afa5fb36d4e2c3f708c6f5dc201e0802aa61f0eaa56e63a62882330b5225dbbaa08721d
data/CHANGELOG.md CHANGED
@@ -9,6 +9,15 @@
9
9
  - ...
10
10
  ---
11
11
 
12
+ ## v0.10.5
13
+ ### Added
14
+ - `Database#last_result` getter method to return the most recent raw mongo result.
15
+ ### Changed/Removed
16
+ - ...
17
+ ### Fixed
18
+ - ...
19
+ ---
20
+
12
21
  ## v0.10.4
13
22
  ### Added
14
23
  - `Database#search_text` method which returns a Hash of `url => text_results` instead of `Wgit::Documents` (like `#search`).
@@ -45,6 +45,9 @@ module Wgit
45
45
  # A custom setter method is also provided for changing the search logic.
46
46
  attr_reader :text_index
47
47
 
48
+ # The raw MongoDB result of the most recent operation.
49
+ attr_reader :last_result
50
+
48
51
  # Initializes a connected database client using the provided
49
52
  # connection_string or ENV['WGIT_CONNECTION_STRING'].
50
53
  #
@@ -185,6 +188,8 @@ module Wgit
185
188
  result = @client[collection].replace_one(query, data_hash, upsert: true)
186
189
 
187
190
  result.matched_count.zero?
191
+ ensure
192
+ @last_result = result
188
193
  end
189
194
 
190
195
  ### Retrieve Data ###
@@ -294,16 +299,12 @@ module Wgit
294
299
  results = retrieve(DOCUMENTS_COLLECTION, query,
295
300
  sort: sort_proj, projection: sort_proj,
296
301
  limit: limit, skip: skip)
297
- return [] if results.count < 1 # respond_to? :empty? == false
298
302
 
299
- # results.respond_to? :map! is false so we use map and overwrite the var.
300
- results = results.map do |mongo_doc|
303
+ results.map do |mongo_doc|
301
304
  doc = Wgit::Document.new(mongo_doc)
302
305
  yield(doc) if block_given?
303
306
  doc
304
307
  end
305
-
306
- results
307
308
  end
308
309
 
309
310
  # Searches the database's Documents for the given query and then searches
@@ -506,21 +507,30 @@ module Wgit
506
507
  # 0 or 1 because urls are unique.
507
508
  def delete(obj)
508
509
  collection, query = get_type_info(obj)
509
- @client[collection].delete_one(query).n
510
+ result = @client[collection].delete_one(query)
511
+ result.n
512
+ ensure
513
+ @last_result = result
510
514
  end
511
515
 
512
516
  # Deletes everything in the urls collection.
513
517
  #
514
518
  # @return [Integer] The number of deleted records.
515
519
  def clear_urls
516
- @client[URLS_COLLECTION].delete_many({}).n
520
+ result = @client[URLS_COLLECTION].delete_many({})
521
+ result.n
522
+ ensure
523
+ @last_result = result
517
524
  end
518
525
 
519
526
  # Deletes everything in the documents collection.
520
527
  #
521
528
  # @return [Integer] The number of deleted records.
522
529
  def clear_docs
523
- @client[DOCUMENTS_COLLECTION].delete_many({}).n
530
+ result = @client[DOCUMENTS_COLLECTION].delete_many({})
531
+ result.n
532
+ ensure
533
+ @last_result = result
524
534
  end
525
535
 
526
536
  # Deletes everything in the urls and documents collections. This will nuke
@@ -588,6 +598,8 @@ module Wgit
588
598
  else
589
599
  raise 'data must be a Hash or an Array of Hashes'
590
600
  end
601
+ ensure
602
+ @last_result = result
591
603
  end
592
604
 
593
605
  # Return if the write to the DB succeeded or not.
@@ -624,8 +636,8 @@ module Wgit
624
636
  sort: {}, projection: {},
625
637
  limit: 0, skip: 0)
626
638
  assert_type(query, Hash)
627
- @client[collection.to_sym].find(query).projection(projection)
628
- .skip(skip).limit(limit).sort(sort)
639
+ @last_result = @client[collection.to_sym].find(query).projection(projection)
640
+ .skip(skip).limit(limit).sort(sort)
629
641
  end
630
642
 
631
643
  # Mutate/update one or more Url or Document records in the DB.
@@ -645,6 +657,8 @@ module Wgit
645
657
  raise 'DB write(s) (update) failed' unless write_succeeded?(result)
646
658
 
647
659
  result.n
660
+ ensure
661
+ @last_result = result
648
662
  end
649
663
 
650
664
  alias num_objects num_records
data/lib/wgit/version.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # @author Michael Telford
7
7
  module Wgit
8
8
  # The current gem version of Wgit.
9
- VERSION = '0.10.4'
9
+ VERSION = '0.10.5'
10
10
 
11
11
  # Returns the current gem version of Wgit as a String.
12
12
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Telford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable