nobrainer 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/no_brainer/autoload.rb +0 -5
- data/lib/no_brainer/config.rb +14 -9
- data/lib/no_brainer/connection.rb +1 -3
- data/lib/no_brainer/criteria.rb +1 -1
- data/lib/no_brainer/criteria/aggregate.rb +2 -2
- data/lib/no_brainer/criteria/cache.rb +8 -3
- data/lib/no_brainer/criteria/core.rb +1 -5
- data/lib/no_brainer/criteria/delete.rb +1 -1
- data/lib/no_brainer/criteria/eager_load.rb +51 -0
- data/lib/no_brainer/criteria/order_by.rb +1 -1
- data/lib/no_brainer/criteria/scope.rb +3 -10
- data/lib/no_brainer/criteria/update.rb +8 -6
- data/lib/no_brainer/criteria/where.rb +50 -13
- data/lib/no_brainer/document.rb +2 -2
- data/lib/no_brainer/document/aliases.rb +0 -8
- data/lib/no_brainer/document/association/belongs_to.rb +6 -2
- data/lib/no_brainer/document/association/core.rb +5 -4
- data/lib/no_brainer/document/association/eager_loader.rb +7 -8
- data/lib/no_brainer/document/association/has_many.rb +22 -8
- data/lib/no_brainer/document/association/has_many_through.rb +12 -3
- data/lib/no_brainer/document/atomic_ops.rb +63 -61
- data/lib/no_brainer/document/attributes.rb +11 -3
- data/lib/no_brainer/document/core.rb +5 -2
- data/lib/no_brainer/document/criteria.rb +14 -5
- data/lib/no_brainer/document/dirty.rb +11 -16
- data/lib/no_brainer/document/index.rb +0 -6
- data/lib/no_brainer/document/index/meta_store.rb +1 -1
- data/lib/no_brainer/document/persistance.rb +12 -2
- data/lib/no_brainer/document/types.rb +13 -12
- data/lib/no_brainer/document/types/binary.rb +0 -4
- data/lib/no_brainer/document/types/boolean.rb +0 -1
- data/lib/no_brainer/document/types/geo.rb +1 -0
- data/lib/no_brainer/document/types/string.rb +3 -0
- data/lib/no_brainer/document/types/text.rb +18 -0
- data/lib/no_brainer/document/validation.rb +31 -6
- data/lib/no_brainer/document/validation/not_null.rb +15 -0
- data/lib/no_brainer/document/{uniqueness.rb → validation/uniqueness.rb} +11 -10
- data/lib/no_brainer/error.rb +20 -23
- data/lib/no_brainer/locale/en.yml +1 -0
- data/lib/no_brainer/lock.rb +114 -0
- data/lib/no_brainer/query_runner/database_on_demand.rb +0 -1
- data/lib/no_brainer/query_runner/missing_index.rb +1 -1
- data/lib/no_brainer/query_runner/run_options.rb +0 -3
- data/lib/no_brainer/query_runner/table_on_demand.rb +2 -3
- data/lib/no_brainer/rql.rb +0 -4
- data/lib/nobrainer.rb +1 -1
- metadata +8 -4
- data/lib/no_brainer/criteria/preload.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f2246b107585644fff659c53223f7c821bbc628
|
4
|
+
data.tar.gz: 9c2b99c8969e58ac8a3e9c447a887ab30d6ee402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d2a9de23fc93e7283618a61107043d02fdf4e04623201e654663e4973f248d20122bdfa79f6818580d71169f7d65f56b2dfb4b75dd26f554ed0094996fe6ff
|
7
|
+
data.tar.gz: 7c16007cb6fd8c4e1b0d9bb1b2a590f4cddb489f78c9215315870cfacea4cda86b6de1b63429a46d9641bb3c77216d0a5108c48f4b78459e06bdee174bbcfa4d
|
data/lib/no_brainer/autoload.rb
CHANGED
@@ -17,9 +17,4 @@ module NoBrainer::Autoload
|
|
17
17
|
constants.each { |constant| autoload constant }
|
18
18
|
constants.each { |constant| include const_get(constant) }
|
19
19
|
end
|
20
|
-
|
21
|
-
def eager_autoload_and_include(*constants)
|
22
|
-
eager_autoload(*constants)
|
23
|
-
constants.each { |constant| include const_get(constant) }
|
24
|
-
end
|
25
20
|
end
|
data/lib/no_brainer/config.rb
CHANGED
@@ -6,27 +6,32 @@ module NoBrainer::Config
|
|
6
6
|
:environment => { :default => ->{ default_environment } },
|
7
7
|
:rethinkdb_url => { :default => ->{ default_rethinkdb_url } },
|
8
8
|
:logger => { :default => ->{ default_logger } },
|
9
|
+
:colorize_logger => { :default => ->{ true }, :valid_values => [true, false] },
|
9
10
|
:warn_on_active_record => { :default => ->{ true }, :valid_values => [true, false] },
|
10
|
-
:auto_create_databases => { :default => ->{ true }, :valid_values => [true, false] },
|
11
|
-
:auto_create_tables => { :default => ->{ true }, :valid_values => [true, false] },
|
12
11
|
:max_retries_on_connection_failure => { :default => ->{ default_max_retries_on_connection_failure } },
|
13
12
|
:durability => { :default => ->{ default_durability }, :valid_values => [:hard, :soft] },
|
13
|
+
:max_string_length => { :default => -> { 255 } },
|
14
14
|
:user_timezone => { :default => ->{ :local }, :valid_values => [:unchanged, :utc, :local] },
|
15
15
|
:db_timezone => { :default => ->{ :utc }, :valid_values => [:unchanged, :utc, :local] },
|
16
|
-
:
|
17
|
-
:distributed_lock_class => { :default => ->{
|
16
|
+
:geo_options => { :default => ->{ {:geo_system => 'WGS84', :unit => 'm'} } },
|
17
|
+
:distributed_lock_class => { :default => ->{ NoBrainer::Lock } },
|
18
|
+
:lock_options => { :default => ->{ { :expire => 60, :timeout => 10 } } },
|
18
19
|
:per_thread_connection => { :default => ->{ false }, :valid_values => [true, false] },
|
19
20
|
:machine_id => { :default => ->{ default_machine_id } },
|
20
|
-
:
|
21
|
+
:criteria_cache_max_entries => { :default => -> { 10_000 } },
|
21
22
|
}
|
22
23
|
|
23
24
|
class << self
|
24
25
|
attr_accessor(*SETTINGS.keys)
|
25
26
|
|
26
|
-
def
|
27
|
-
STDERR.puts "[NoBrainer] config.
|
28
|
-
STDERR.puts "[NoBrainer]
|
29
|
-
|
27
|
+
def auto_create_databases=(value)
|
28
|
+
STDERR.puts "[NoBrainer] config.auto_create_databases is no longer active."
|
29
|
+
STDERR.puts "[NoBrainer] The current behavior is now to always auto create databases"
|
30
|
+
end
|
31
|
+
|
32
|
+
def auto_create_tables=(value)
|
33
|
+
STDERR.puts "[NoBrainer] config.auto_create_tables is no longer active."
|
34
|
+
STDERR.puts "[NoBrainer] The current behavior is now to always auto create tables"
|
30
35
|
end
|
31
36
|
|
32
37
|
def apply_defaults
|
@@ -52,11 +52,9 @@ class NoBrainer::Connection
|
|
52
52
|
# database (drop)
|
53
53
|
def purge!
|
54
54
|
table_list.each do |table_name|
|
55
|
-
next if table_name
|
55
|
+
next if table_name == 'nobrainer_index_meta' # keeping because indexes are not going away
|
56
56
|
NoBrainer.run { |r| r.table(table_name).delete }
|
57
57
|
end
|
58
58
|
true
|
59
|
-
rescue RuntimeError => e
|
60
|
-
raise e unless e.message =~ /No entry with that name/
|
61
59
|
end
|
62
60
|
end
|
data/lib/no_brainer/criteria.rb
CHANGED
@@ -4,5 +4,5 @@ class NoBrainer::Criteria
|
|
4
4
|
extend NoBrainer::Autoload
|
5
5
|
autoload_and_include :Core, :Raw, :AfterFind, :Where, :OrderBy, :Limit,
|
6
6
|
:Pluck, :Count, :Delete, :Enumerable, :First, :Aggregate,
|
7
|
-
:
|
7
|
+
:EagerLoad, :Update, :Cache, :Index, :Extend, :Scope
|
8
8
|
end
|
@@ -2,11 +2,11 @@ module NoBrainer::Criteria::Aggregate
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
def min(*a, &b)
|
5
|
-
|
5
|
+
order_by(a, &b).first
|
6
6
|
end
|
7
7
|
|
8
8
|
def max(*a, &b)
|
9
|
-
|
9
|
+
order_by(a, &b).last
|
10
10
|
end
|
11
11
|
|
12
12
|
def sum(*a, &b)
|
@@ -37,15 +37,20 @@ module NoBrainer::Criteria::Cache
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def each(options={}, &block)
|
40
|
-
return super unless with_cache? && !options[:no_cache] && block
|
40
|
+
return super unless with_cache? && !options[:no_cache] && block && !@cache_too_small
|
41
41
|
return @cache.each(&block) if @cache
|
42
42
|
|
43
43
|
cache = []
|
44
44
|
super(options.merge(:no_cache => true)) do |instance|
|
45
45
|
block.call(instance)
|
46
|
-
cache << instance
|
46
|
+
cache << instance unless @cache_too_small
|
47
|
+
|
48
|
+
if cache.size > NoBrainer::Config.criteria_cache_max_entries
|
49
|
+
cache = []
|
50
|
+
@cache_too_small = true
|
51
|
+
end
|
47
52
|
end
|
48
|
-
@cache = cache
|
53
|
+
@cache = cache unless @cache_too_small
|
49
54
|
self
|
50
55
|
end
|
51
56
|
|
@@ -47,7 +47,7 @@ module NoBrainer::Criteria::Core
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def merge(criteria, options={})
|
50
|
-
dup.
|
50
|
+
dup.merge!(criteria, options)
|
51
51
|
end
|
52
52
|
|
53
53
|
def ==(other)
|
@@ -102,10 +102,6 @@ module NoBrainer::Criteria::Core
|
|
102
102
|
b
|
103
103
|
end
|
104
104
|
|
105
|
-
def merge_hash(a, b)
|
106
|
-
a ? a.merge(b) : b
|
107
|
-
end
|
108
|
-
|
109
105
|
def append_array(a, b)
|
110
106
|
a ? a+b : b
|
111
107
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module NoBrainer::Criteria::EagerLoad
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included { criteria_option :eager_load, :merge_with => :append_array }
|
5
|
+
|
6
|
+
def eager_load(*values)
|
7
|
+
chain({:eager_load => values}, :copy_cache_from => self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def preload(*values)
|
11
|
+
STDERR.puts "[NoBrainer] `preload' is deprecated and will be removed, please use `eager_load' instead"
|
12
|
+
eager_load(*values)
|
13
|
+
end
|
14
|
+
|
15
|
+
def merge!(criteria, options={})
|
16
|
+
super.tap do
|
17
|
+
# If we already have some cached documents, and we need to so some eager
|
18
|
+
# loading, then we it now. It's easier than doing it lazily.
|
19
|
+
if self.cached? && criteria.options[:eager_load].present?
|
20
|
+
perform_eager_load(@cache)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def each(options={}, &block)
|
26
|
+
return super unless should_eager_load? && !options[:no_eager_loading] && block
|
27
|
+
|
28
|
+
docs = []
|
29
|
+
super(options.merge(:no_eager_loading => true)) { |doc| docs << doc }
|
30
|
+
# TODO batch the eager loading with NoBrainer::Config.criteria_cache_max_entries
|
31
|
+
perform_eager_load(docs)
|
32
|
+
docs.each(&block)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def should_eager_load?
|
39
|
+
@options[:eager_load].present? && !raw?
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_one(criteria)
|
43
|
+
super.tap { |doc| perform_eager_load([doc]) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def perform_eager_load(docs)
|
47
|
+
if should_eager_load? && docs.present?
|
48
|
+
NoBrainer::Document::Association::EagerLoader.new.eager_load(docs, @options[:eager_load])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -134,6 +134,6 @@ module NoBrainer::Criteria::OrderBy
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def raise_bad_rule(rule)
|
137
|
-
raise "
|
137
|
+
raise "order_by() takes arguments such as `:field1 => :desc, :field2 => :asc', not `#{rule}'"
|
138
138
|
end
|
139
139
|
end
|
@@ -24,21 +24,14 @@ module NoBrainer::Criteria::Scope
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
def should_apply_default_scope?
|
28
|
-
model.default_scope_proc && @options[:use_default_scope] != false
|
29
|
-
end
|
30
|
-
|
31
27
|
def _apply_default_scope
|
32
|
-
return
|
33
|
-
|
34
|
-
raise "Mixing model issue. Contact developer." if [criteria.model, self.model].compact.uniq.size == 2
|
35
|
-
criteria.merge(self)
|
28
|
+
return self if @options[:use_default_scope] == false
|
29
|
+
(model.default_scopes.map(&:call).compact + [self]).reduce(:merge)
|
36
30
|
end
|
37
31
|
|
38
32
|
module ClassMethods
|
39
33
|
def _finalize_criteria(base)
|
40
|
-
|
41
|
-
criteria.__send__(:_apply_default_scope) || criteria
|
34
|
+
super.__send__(:_apply_default_scope)
|
42
35
|
end
|
43
36
|
end
|
44
37
|
end
|
@@ -2,18 +2,20 @@ module NoBrainer::Criteria::Update
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
def update_all(*a, &b)
|
5
|
-
|
6
|
-
run { without_ordering.without_plucking.to_rql.update(*a, &b) }
|
5
|
+
perform_update(:update, a, b)
|
7
6
|
end
|
8
7
|
|
9
8
|
def replace_all(*a, &b)
|
10
|
-
|
11
|
-
run { without_ordering.without_plucking.to_rql.replace(*a, &b) }
|
9
|
+
perform_update(:replace, a, b)
|
12
10
|
end
|
13
11
|
|
14
12
|
private
|
15
13
|
|
16
|
-
def
|
17
|
-
|
14
|
+
def perform_update(type, args, block)
|
15
|
+
args[0] = model.persistable_attributes(args[0]) if !args.empty? && args.first.is_a?(Hash)
|
16
|
+
# can't use without_distinct when passed a block as the operation may be
|
17
|
+
# performed many times, which might not be idempotent.
|
18
|
+
clause = block ? self : without_distinct
|
19
|
+
run { clause.without_plucking.to_rql.__send__(type, *args, &block) }
|
18
20
|
end
|
19
21
|
end
|
@@ -8,9 +8,11 @@ module NoBrainer::Criteria::Where
|
|
8
8
|
Symbol::Decoration.register(*CHAINABLE_OPERATORS, :chainable => true)
|
9
9
|
|
10
10
|
extend ActiveSupport::Concern
|
11
|
+
include ActiveModel::ForbiddenAttributesProtection
|
11
12
|
|
12
13
|
included do
|
13
14
|
criteria_option :where_ast, :merge_with => NoBrainer::Criteria::Where.method(:merge_where_ast)
|
15
|
+
criteria_option :without_distinct, :merge_with => :set_scalar
|
14
16
|
end
|
15
17
|
|
16
18
|
def where(*args, &block)
|
@@ -38,6 +40,11 @@ module NoBrainer::Criteria::Where
|
|
38
40
|
where_index_finder.strategy.try(:rql_op)
|
39
41
|
end
|
40
42
|
|
43
|
+
def without_distinct(value = true)
|
44
|
+
# helper for delete_all which can't operate on distinct
|
45
|
+
chain(:without_distinct => value)
|
46
|
+
end
|
47
|
+
|
41
48
|
private
|
42
49
|
|
43
50
|
class MultiOperator < Struct.new(:op, :clauses)
|
@@ -157,11 +164,14 @@ module NoBrainer::Criteria::Where
|
|
157
164
|
case association
|
158
165
|
when NoBrainer::Document::Association::BelongsTo::Metadata
|
159
166
|
target_model = association.target_model
|
160
|
-
|
161
|
-
|
167
|
+
unless value.is_a?(target_model)
|
168
|
+
opts = { :model => model, :attr_name => key, :type => target_model, :value => value }
|
169
|
+
raise NoBrainer::Error::InvalidType.new(opts)
|
170
|
+
end
|
162
171
|
value.pk_value
|
163
172
|
else
|
164
173
|
case op
|
174
|
+
when :defined then NoBrainer::Boolean.nobrainer_cast_user_to_model(value)
|
165
175
|
when :intersects
|
166
176
|
raise "Use a geo object with `intersects`" unless value.is_a?(NoBrainer::Geo::Base)
|
167
177
|
value
|
@@ -225,6 +235,7 @@ module NoBrainer::Criteria::Where
|
|
225
235
|
end
|
226
236
|
|
227
237
|
def parse_clause(clause)
|
238
|
+
clause = sanitize_for_mass_assignment(clause)
|
228
239
|
case clause
|
229
240
|
when Array then MultiOperator.new(:and, clause.map { |c| parse_clause(c) })
|
230
241
|
when Hash then MultiOperator.new(:and, clause.map { |k,v| parse_clause_stub(k,v) })
|
@@ -240,9 +251,11 @@ module NoBrainer::Criteria::Where
|
|
240
251
|
|
241
252
|
def parse_clause_stub(key, value)
|
242
253
|
case key
|
243
|
-
when :and
|
244
|
-
when :or
|
245
|
-
when :
|
254
|
+
when :and then parse_multi_value(:and, value)
|
255
|
+
when :or then parse_multi_value(:or, value)
|
256
|
+
when :_and then parse_multi_value(:and, value, :safe => true)
|
257
|
+
when :_or then parse_multi_value(:or, value, :safe => true)
|
258
|
+
when :not then UnaryOperator.new(:not, parse_clause(value))
|
246
259
|
when String, Symbol then parse_clause_stub_eq(key, value)
|
247
260
|
when Symbol::Decoration then
|
248
261
|
case key.decorator
|
@@ -258,14 +271,38 @@ module NoBrainer::Criteria::Where
|
|
258
271
|
end
|
259
272
|
end
|
260
273
|
|
274
|
+
def parse_multi_value(op, value, options={})
|
275
|
+
raise "The `#{op}' operator takes an array as argument" unless value.is_a?(Array)
|
276
|
+
if value.size == 1 && value.first.is_a?(Hash) && !options[:safe]
|
277
|
+
raise "The `#{op}' operator was provided an array with a single hash element.\n" +
|
278
|
+
"In Ruby, [:a => :b, :c => :d] means [{:a => :b, :c => :d}] which is not the same as [{:a => :b}, {:c => :d}].\n" +
|
279
|
+
"To prevent mistakes, the former construct is prohibited as you probably mean the latter.\n" +
|
280
|
+
"However, if you know what you are doing, you can use the `_#{op}' operator instead."
|
281
|
+
end
|
282
|
+
MultiOperator.new(op, value.map { |v| parse_clause(v) })
|
283
|
+
end
|
284
|
+
|
261
285
|
def parse_clause_stub_eq(key, value)
|
262
286
|
case value
|
263
287
|
when Range then instantiate_binary_op(key, :between, value)
|
264
|
-
when Regexp then instantiate_binary_op(key, :match, value
|
288
|
+
when Regexp then instantiate_binary_op(key, :match, translate_regexp_to_re2_syntax(value))
|
265
289
|
else instantiate_binary_op(key, :eq, value)
|
266
290
|
end
|
267
291
|
end
|
268
292
|
|
293
|
+
def translate_regexp_to_re2_syntax(value)
|
294
|
+
# Ruby always uses what RE2 calls "multiline mode" (the "m" flag),
|
295
|
+
# meaning that "foo\nbar" matches /^bar$/.
|
296
|
+
#
|
297
|
+
# Ruby's /m modifier means that . matches \n and corresponds to RE2's "s" flag.
|
298
|
+
|
299
|
+
flags = "m"
|
300
|
+
flags << "s" if value.options & Regexp::MULTILINE != 0
|
301
|
+
flags << "i" if value.options & Regexp::IGNORECASE != 0
|
302
|
+
|
303
|
+
"(?#{flags})#{value.source}"
|
304
|
+
end
|
305
|
+
|
269
306
|
def instantiate_binary_op(key, op, value)
|
270
307
|
case key
|
271
308
|
when Symbol::Decoration then BinaryOperator.new(key.symbol, key.decorator, op, value, self.model)
|
@@ -274,8 +311,8 @@ module NoBrainer::Criteria::Where
|
|
274
311
|
end
|
275
312
|
|
276
313
|
class IndexFinder < Struct.new(:criteria, :ast, :strategy)
|
277
|
-
class Strategy < Struct.new(:rql_op, :index, :ast, :rql_proc); end
|
278
|
-
class IndexStrategy < Struct.new(:criteria_ast, :optimized_clauses, :index, :rql_op, :rql_args, :rql_options)
|
314
|
+
class Strategy < Struct.new(:index_finder, :rql_op, :index, :ast, :rql_proc); end
|
315
|
+
class IndexStrategy < Struct.new(:index_finder, :criteria_ast, :optimized_clauses, :index, :rql_op, :rql_args, :rql_options)
|
279
316
|
def ast
|
280
317
|
MultiOperator.new(criteria_ast.op, criteria_ast.clauses - optimized_clauses)
|
281
318
|
end
|
@@ -287,7 +324,7 @@ module NoBrainer::Criteria::Where
|
|
287
324
|
r = r.map { |i| i['doc'] } if rql_op == :get_nearest
|
288
325
|
# TODO distinct: waiting for issue #3345
|
289
326
|
# TODO coerce_to: waiting for issue #3346
|
290
|
-
r = r.coerce_to('array').distinct if index.multi
|
327
|
+
r = r.coerce_to('array').distinct if index.multi && !index_finder.criteria.options[:without_distinct]
|
291
328
|
r
|
292
329
|
end
|
293
330
|
end
|
@@ -327,7 +364,7 @@ module NoBrainer::Criteria::Where
|
|
327
364
|
when :between then [:between, [clause.value.min, clause.value.max],
|
328
365
|
:left_bound => :closed, :right_bound => :closed]
|
329
366
|
end
|
330
|
-
IndexStrategy.new(ast, [clause], index, *args)
|
367
|
+
IndexStrategy.new(self, ast, [clause], index, *args)
|
331
368
|
end.compact.sort_by { |strat| usable_indexes.values.index(strat.index) }.first
|
332
369
|
end
|
333
370
|
|
@@ -339,7 +376,7 @@ module NoBrainer::Criteria::Where
|
|
339
376
|
indexed_clauses = index.what.map { |field| clauses[field] }
|
340
377
|
next unless indexed_clauses.all? { |c| c.try(:compatible_with_index?, index) }
|
341
378
|
|
342
|
-
return IndexStrategy.new(ast, indexed_clauses, index, :get_all, [indexed_clauses.map(&:value)])
|
379
|
+
return IndexStrategy.new(self, ast, indexed_clauses, index, :get_all, [indexed_clauses.map(&:value)])
|
343
380
|
end
|
344
381
|
return nil
|
345
382
|
end
|
@@ -363,7 +400,7 @@ module NoBrainer::Criteria::Where
|
|
363
400
|
options[:left_bound] = {:gt => :open, :ge => :closed}[left_bound.op] if left_bound
|
364
401
|
options[:right_bound] = {:lt => :open, :le => :closed}[right_bound.op] if right_bound
|
365
402
|
|
366
|
-
return IndexStrategy.new(ast, [left_bound, right_bound].compact, index, :between,
|
403
|
+
return IndexStrategy.new(self, ast, [left_bound, right_bound].compact, index, :between,
|
367
404
|
[left_bound.try(:value), right_bound.try(:value)], options)
|
368
405
|
end
|
369
406
|
return nil
|
@@ -386,7 +423,7 @@ module NoBrainer::Criteria::Where
|
|
386
423
|
end.reduce(:union).distinct
|
387
424
|
end
|
388
425
|
|
389
|
-
Strategy.new(:union, strategies.map(&:index), nil, rql_proc)
|
426
|
+
Strategy.new(self, :union, strategies.map(&:index), nil, rql_proc)
|
390
427
|
end
|
391
428
|
|
392
429
|
def find_strategy
|
data/lib/no_brainer/document.rb
CHANGED
@@ -4,8 +4,8 @@ module NoBrainer::Document
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
extend NoBrainer::Autoload
|
6
6
|
|
7
|
-
autoload_and_include :Core, :StoreIn, :InjectionLayer, :Attributes, :Readonly,
|
8
|
-
:Persistance, :
|
7
|
+
autoload_and_include :Core, :StoreIn, :InjectionLayer, :Attributes, :Readonly,
|
8
|
+
:Persistance, :Validation, :Types, :Callbacks, :Dirty, :PrimaryKey,
|
9
9
|
:Association, :Serialization, :Criteria, :Polymorphic, :Index, :Aliases,
|
10
10
|
:MissingAttributes, :LazyFetch, :AtomicOps
|
11
11
|
|
@@ -19,14 +19,6 @@ module NoBrainer::Document::Aliases
|
|
19
19
|
super
|
20
20
|
end
|
21
21
|
|
22
|
-
def field(attr, options={})
|
23
|
-
if options[:as]
|
24
|
-
STDERR.puts "[NoBrainer] `:as' is deprecated and will be removed. Please use `:store_as' instead (from the #{self} model)"
|
25
|
-
options[:store_as] = options.delete(:as)
|
26
|
-
end
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
22
|
def _remove_field(attr, options={})
|
31
23
|
super
|
32
24
|
|