mongo_ql 1.0.5 → 1.0.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: b9bf8890c39c8a91c22cbf5125294c46f5f5d56cb347872e1413739708ef35ad
4
- data.tar.gz: e5a07cce5320dd7e5a1b9d8eb47d3418992d57b35fe629f01bcfb0fefb218bf7
3
+ metadata.gz: 397c8071669a33bfe85662de3439d9746d26bcb80ccb69dcc602471224da7f12
4
+ data.tar.gz: 683ad4555c980a6ce2593a2dbf1efa20f182d836e0ca16ea98511638dadd8502
5
5
  SHA512:
6
- metadata.gz: 922f53c459b910bbaedde04c798f6e3ac270f3ba7d691c4563685adbb9a765183eefc5fc81921fe502f8e3b015d8f5883f8733ecec2ca9822a1a4d33e37fc7ec
7
- data.tar.gz: d5517cffc1e722928f91210708a8781ac7dcec86b3decec423031ea5dcfee1828a9c41e4e1bef20621d1a3a99b669bd2c00993b2beb145aab8a69ff84f6d9863
6
+ metadata.gz: f1fe54f5ffad72f4184202af5ab4cf5c923f6e79bb4e9b0de73d618668319f3f63c43a1529bbf73771ec7ca5886c393d623cc70ddca3b8e0a7c466fe003856f3
7
+ data.tar.gz: 563766df5b880b08870f9b084fbb866ce9883fc79f20a0d202f508ca5560f483053a37f74c2565a3b92e6fbe859c6ff1d3e4bc8b05892f2a5f767f283361ced5
@@ -24,10 +24,6 @@ module MongoQL
24
24
  field_name.to_s
25
25
  end
26
26
 
27
- def name
28
- field_name.to_s
29
- end
30
-
31
27
  def dsc
32
28
  Expression::Descend.new(self)
33
29
  end
@@ -14,12 +14,14 @@ module MongoQL
14
14
  def initialize(val)
15
15
  Expression::ValueNode.valid!(val)
16
16
  @value = val
17
+ convert_to_date_if_possible
17
18
  end
18
19
 
19
20
  def to_ast
20
21
  case value
21
22
  when Date, DateTime
22
- Expression::ValueNode.new(value.iso8601).to_date.to_ast
23
+ # Expression::ValueNode.new(value.iso8601).to_date.to_ast
24
+ { "$toDate" => value.iso8601 }
23
25
  when MongoQL::Expression::ValueNode
24
26
  value.to_ast
25
27
  else
@@ -27,6 +29,12 @@ module MongoQL
27
29
  end
28
30
  end
29
31
 
32
+ def convert_to_date_if_possible
33
+ self.value = DateTime.iso8601(value)
34
+ rescue => _
35
+ value
36
+ end
37
+
30
38
  def self.valid?(value)
31
39
  SUPPORTED_TYPES.any? { |type| value.is_a?(type) }
32
40
  end
@@ -81,8 +81,8 @@ module MongoQL
81
81
  else
82
82
  if from&.respond_to?(:collection)
83
83
  from&.collection&.name
84
- elsif from&.respond_to?(:name)
85
- from.name
84
+ elsif from&.respond_to?(:field_name)
85
+ from.field_name
86
86
  else
87
87
  raise ArgumentError, "#{from} is not a valid collection"
88
88
  end
@@ -9,6 +9,18 @@ module MongoQL
9
9
  @injected_vars = {}
10
10
  end
11
11
 
12
+ def scope(mongo_scope)
13
+ criteria = nil
14
+ if mongo_scope.respond_to?(:all)
15
+ criteria = mongo_scope.all.selector.transform_keys { |k| k.to_sym }
16
+ end
17
+
18
+ if mongo_scope.is_a?(Hash)
19
+ criteria = mongo_scope.transform_keys { |k| k.to_sym }
20
+ end
21
+ where(**criteria) if criteria
22
+ end
23
+
12
24
  def where(*args)
13
25
  pipeline << Stage::Match.new(self, *args)
14
26
  end
@@ -69,7 +81,7 @@ module MongoQL
69
81
  pipeline.map(&:to_ast)
70
82
  end
71
83
 
72
- %w(where match project select sort flatten unwind lookup join).each do |m|
84
+ %w(scope where match project select sort flatten unwind lookup join).each do |m|
73
85
  alias_method :"#{m.capitalize}", m
74
86
  end
75
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MongoQL
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_ql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xizheng Ding
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake