mongrep 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 69914b4493a7de6bb8566f431244fc57f17a8a20
4
- data.tar.gz: 5f24300241239d49e2bacbbcf6d3ce99d8c12327
3
+ metadata.gz: e5213c7c449784c621feca34ded1df39c9b91dc2
4
+ data.tar.gz: 1250f6b7535011f3a4e2c5627dae1fc8be128928
5
5
  SHA512:
6
- metadata.gz: 96db1d696abc053ea35d709f4cb7694bf555fbdd1d969265a19cac103eefb2f889174c63f8e79158d699abe474a3b94ee3601ad06e1d76a16bc88a1ac5f5ae99
7
- data.tar.gz: d695e3946bed16a8caa294fa96971a51073226ae44f78a2f5afecd95cb06296f8b423e856ca696e65513f9f9f5c3466b37d39b7d14d7a3e9ffb98d2751642d6b
6
+ metadata.gz: 0d288ca4f5d697ae1c439de27020239f402ae85858ef77ea55ae82c58b5287a77a8e400f73403be961dc05750e84537c2ad4012c7f2aa27d2a8b6ce989f8d486
7
+ data.tar.gz: 2d4f527de3dbf265920709f3ca8eeb00575bed19f88377d0fff939e6aba6143d42b195708eec96d99f4489e73554aeeee27666ee68cbf7a858c418b70a625d4d
data/.rubocop.yml CHANGED
@@ -4,3 +4,6 @@ Metrics/BlockLength:
4
4
  Exclude:
5
5
  - 'spec/**/*.rb'
6
6
  - '*.gemspec'
7
+
8
+ RSpec/NestedGroups:
9
+ MaxNesting: 3
data/.travis.yml CHANGED
@@ -2,4 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
+ services:
6
+ - mongodb
5
7
  before_install: gem install bundler -v 1.12.5
data/README.md CHANGED
@@ -17,7 +17,7 @@ And then execute:
17
17
 
18
18
  ## Documentation
19
19
 
20
- API docs are available at https://rubydocs.info/mongrep
20
+ API docs are available at http://rubydoc.info/github/meso-unimpressed/mongrep
21
21
 
22
22
  ## Development
23
23
 
data/lib/mongrep/query.rb CHANGED
@@ -60,7 +60,16 @@ module Mongrep
60
60
  self | self.class.new(query_hash)
61
61
  end
62
62
 
63
- alias and where
63
+ # Combines self with the given query hash by using the MongoDB $and
64
+ # operator
65
+ # @param query_hash [Hash] The query hash to combine with the query
66
+ # @return [Query] A new Query resulting in the combination of the
67
+ # given query hash and the existing one
68
+ # @example
69
+ # query.where(foo: { bar: 'foo' }).and(foo: { foo: 'bar' })
70
+ def and(query_hash)
71
+ self.class.new(:$and => [@query_hash, query_hash])
72
+ end
64
73
 
65
74
  # @return [Hash] The underlying query hash
66
75
  def to_h
@@ -29,6 +29,13 @@ module Mongrep
29
29
  end
30
30
  end
31
31
 
32
+ # @return [Integer] The amount of documents in this result
33
+ def count
34
+ @collection_view.count
35
+ ensure
36
+ @collection_view.close_query
37
+ end
38
+
32
39
  # Iterates over the query result
33
40
  # @yieldparam item [Model] A model representing a document from the
34
41
  # query result
@@ -36,8 +43,12 @@ module Mongrep
36
43
  def each
37
44
  return enum_for(:each) unless block_given?
38
45
 
39
- @collection_view.each do |document|
40
- yield @model_class.new(document)
46
+ begin
47
+ @collection_view.each do |document|
48
+ yield @model_class.new(document)
49
+ end
50
+ ensure
51
+ @collection_view.close_query
41
52
  end
42
53
  end
43
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Mongrep
3
3
  # The current version of this gem
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongrep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Reinert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler