nobrainer 0.25.0 → 0.25.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 +4 -4
- data/lib/no_brainer/criteria.rb +2 -2
- data/lib/no_brainer/criteria/changes.rb +16 -0
- data/lib/no_brainer/criteria/order_by.rb +17 -16
- data/lib/no_brainer/document/criteria.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71e9e6216a8508d483d0c0769b6d8f5137b5f2c2
|
|
4
|
+
data.tar.gz: 91cc415c1d35b3120fc94edfc322bdc30652aa30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4a4656ab19c63e12e194b3c90dd7f25ffc806cfefee029a352e22deccca5908029bf06f14af097d8ebd069ef5eb0a923550d7411dc520fdb2fa8ef2e34378d6
|
|
7
|
+
data.tar.gz: 37f77aef1ca56aeda705659162bab344f4c1e6495ea0c9fe5682ac7a3276eaee642b9313153ecbb80caf839054a499db19c3dd20eb144820ea0a9a97cf1e7f50
|
data/lib/no_brainer/criteria.rb
CHANGED
|
@@ -4,6 +4,6 @@ class NoBrainer::Criteria
|
|
|
4
4
|
extend NoBrainer::Autoload
|
|
5
5
|
autoload_and_include :Core, :Run, :Raw, :Scope, :AfterFind, :Where, :OrderBy,
|
|
6
6
|
:Limit, :Pluck, :Count, :Delete, :Enumerable, :Find,
|
|
7
|
-
:First, :FirstOrCreate, :
|
|
8
|
-
:Cache, :Index, :Extend
|
|
7
|
+
:First, :FirstOrCreate, :Changes, :Aggregate, :EagerLoad,
|
|
8
|
+
:Update, :Cache, :Index, :Extend
|
|
9
9
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module NoBrainer::Criteria::Changes
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
def changes(*args)
|
|
5
|
+
return finalized_criteria.changes(*args) unless finalized?
|
|
6
|
+
|
|
7
|
+
# We won't do any instantiations with attributes for now.
|
|
8
|
+
raise 'Please use .raw.changes()' unless raw?
|
|
9
|
+
|
|
10
|
+
# We can't have implicit sorting as eager streams are not
|
|
11
|
+
# supported by r.changes().
|
|
12
|
+
criteria = self
|
|
13
|
+
criteria = criteria.without_ordering if ordering_mode == :implicit
|
|
14
|
+
run { criteria.to_rql.changes(*args) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -2,7 +2,8 @@ module NoBrainer::Criteria::OrderBy
|
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
4
|
# The latest order_by() wins
|
|
5
|
-
included { criteria_option :order_by, :ordering_mode, :
|
|
5
|
+
included { criteria_option :order_by, :ordering_mode, :reversed_ordering,
|
|
6
|
+
:merge_with => :set_scalar }
|
|
6
7
|
|
|
7
8
|
def order_by(*rules, &block)
|
|
8
9
|
# Note: We are relying on the fact that Hashes are ordered (since 1.9)
|
|
@@ -19,7 +20,8 @@ module NoBrainer::Criteria::OrderBy
|
|
|
19
20
|
|
|
20
21
|
rules.keys.each { |k| model.ensure_valid_key!(k) unless k.is_a?(Proc) } if model
|
|
21
22
|
|
|
22
|
-
chain(:order_by => rules, :ordering_mode => :
|
|
23
|
+
chain(:order_by => rules, :ordering_mode => :explicit,
|
|
24
|
+
:reversed_ordering => false)
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def without_ordering
|
|
@@ -27,12 +29,7 @@ module NoBrainer::Criteria::OrderBy
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def reverse_order
|
|
30
|
-
chain(:
|
|
31
|
-
when nil then :reversed
|
|
32
|
-
when :normal then :reversed
|
|
33
|
-
when :reversed then :normal
|
|
34
|
-
when :disabled then :disabled
|
|
35
|
-
end)
|
|
32
|
+
chain(:reversed_ordering => !@options[:reversed_ordering])
|
|
36
33
|
end
|
|
37
34
|
|
|
38
35
|
def order_by_indexed?
|
|
@@ -45,16 +42,21 @@ module NoBrainer::Criteria::OrderBy
|
|
|
45
42
|
|
|
46
43
|
private
|
|
47
44
|
|
|
48
|
-
def
|
|
49
|
-
@options[:
|
|
45
|
+
def ordering_mode
|
|
46
|
+
@options[:ordering_mode] || :implicit
|
|
50
47
|
end
|
|
51
48
|
|
|
52
49
|
def reverse_order?
|
|
53
|
-
|
|
50
|
+
!!@options[:reversed_ordering]
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
def
|
|
57
|
-
|
|
53
|
+
def effective_order
|
|
54
|
+
# reversing the order happens later.
|
|
55
|
+
case ordering_mode
|
|
56
|
+
when :disabled then nil
|
|
57
|
+
when :explicit then @options[:order_by]
|
|
58
|
+
when :implicit then model && {model.pk_name => :asc}
|
|
59
|
+
end
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
class IndexFinder < Struct.new(:criteria, :index_name, :rql_proc)
|
|
@@ -63,7 +65,7 @@ module NoBrainer::Criteria::OrderBy
|
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def first_key
|
|
66
|
-
@first_key ||= criteria.__send__(:effective_order).first.try(:[], 0)
|
|
68
|
+
@first_key ||= criteria.__send__(:effective_order).to_a.first.try(:[], 0)
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
def first_key_indexable?
|
|
@@ -96,9 +98,8 @@ module NoBrainer::Criteria::OrderBy
|
|
|
96
98
|
|
|
97
99
|
def compile_rql_pass1
|
|
98
100
|
rql = super
|
|
99
|
-
return rql unless should_order?
|
|
100
101
|
_effective_order = effective_order
|
|
101
|
-
return rql
|
|
102
|
+
return rql unless _effective_order.present?
|
|
102
103
|
|
|
103
104
|
rql_rules = _effective_order.map do |k,v|
|
|
104
105
|
if order_by_index_finder.index_name == k
|
|
@@ -29,6 +29,7 @@ module NoBrainer::Document::Criteria
|
|
|
29
29
|
:first_or_create, :first_or_create!, # FirstOrCreate
|
|
30
30
|
:min, :max, :sum, :avg, # Aggregate
|
|
31
31
|
:update_all, :replace_all, # Update
|
|
32
|
+
:changes, # Changes
|
|
32
33
|
:pluck, :without, :lazy_fetch, :without_plucking, # Pluck
|
|
33
34
|
:find_by?, :find_by, :find_by!, :find?, :find, :find!, # Find
|
|
34
35
|
:to => :all
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nobrainer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.25.
|
|
4
|
+
version: 0.25.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolas Viennot
|
|
@@ -97,6 +97,7 @@ files:
|
|
|
97
97
|
- lib/no_brainer/criteria/after_find.rb
|
|
98
98
|
- lib/no_brainer/criteria/aggregate.rb
|
|
99
99
|
- lib/no_brainer/criteria/cache.rb
|
|
100
|
+
- lib/no_brainer/criteria/changes.rb
|
|
100
101
|
- lib/no_brainer/criteria/core.rb
|
|
101
102
|
- lib/no_brainer/criteria/count.rb
|
|
102
103
|
- lib/no_brainer/criteria/delete.rb
|