rokaki 0.8.1 → 0.8.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rokaki/filter_model.rb +9 -6
- data/lib/rokaki/filter_model/nested_filter.rb +4 -3
- data/lib/rokaki/filterable.rb +4 -0
- data/lib/rokaki/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44e54fda626422f9ed27d25aa30aa7f6303722a16b0bb931b6aeead9965b380f
|
4
|
+
data.tar.gz: 2b5a2ea0ce4284e84fcf006071b5831e41df8dfbd83399be23fd62f2cae7ad9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '039a420452518968761d8eff610603a643825fa98de17d51cb038f6fcd79f4870b898688c5bbc6fc61a193ccc21a6cd86b7a50027aa6219520fa1cd3b25469d6'
|
7
|
+
data.tar.gz: 5c69385b228a28f6378b2c8a4e584e597c6e80b5781b634fd8ca977e16f67d65c64c4ca16a1f6ff2bfe6c0cd3a55410033eabe2ac8f195fc46d23cba2ac7c624
|
data/lib/rokaki/filter_model.rb
CHANGED
@@ -27,9 +27,10 @@ module Rokaki
|
|
27
27
|
|
28
28
|
def filter_map(model, query_key, options)
|
29
29
|
filter_model(model)
|
30
|
-
@
|
30
|
+
@filter_map_query_key = query_key
|
31
31
|
|
32
32
|
@_filter_db = options[:db] || :postgres
|
33
|
+
@_filter_mode = options[:mode] || :and
|
33
34
|
like(options[:like]) if options[:like]
|
34
35
|
ilike(options[:ilike]) if options[:ilike]
|
35
36
|
filters(*options[:match]) if options[:match]
|
@@ -37,16 +38,18 @@ module Rokaki
|
|
37
38
|
|
38
39
|
def filter(model, options)
|
39
40
|
filter_model(model)
|
41
|
+
@filter_map_query_key = nil
|
40
42
|
|
41
43
|
@_filter_db = options[:db] || :postgres
|
44
|
+
@_filter_mode = options[:mode] || :and
|
42
45
|
like(options[:like]) if options[:like]
|
43
46
|
ilike(options[:ilike]) if options[:ilike]
|
44
47
|
filters(*options[:match]) if options[:match]
|
45
48
|
end
|
46
49
|
|
47
50
|
def filters(*filter_keys)
|
48
|
-
if @
|
49
|
-
define_filter_map(@
|
51
|
+
if @filter_map_query_key
|
52
|
+
define_filter_map(@filter_map_query_key, *filter_keys)
|
50
53
|
else
|
51
54
|
define_filter_keys(*filter_keys)
|
52
55
|
end
|
@@ -100,9 +103,9 @@ module Rokaki
|
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
103
|
-
def associated_table(association)
|
104
|
-
|
105
|
-
end
|
106
|
+
# def associated_table(association)
|
107
|
+
# @model.reflect_on_association(association).klass.table_name
|
108
|
+
# end
|
106
109
|
|
107
110
|
def filter_model(model_class)
|
108
111
|
@model = (model_class.is_a?(Class) ? model_class : Object.const_get(model_class.capitalize))
|
@@ -4,7 +4,7 @@ require 'active_support/inflector'
|
|
4
4
|
module Rokaki
|
5
5
|
module FilterModel
|
6
6
|
class NestedFilter
|
7
|
-
def initialize(filter_key_object:, prefix:, infix:, like_semantics:, i_like_semantics:, db:)
|
7
|
+
def initialize(filter_key_object:, prefix:, infix:, like_semantics:, i_like_semantics:, db:, mode: :and)
|
8
8
|
@filter_key_object = filter_key_object
|
9
9
|
@prefix = prefix
|
10
10
|
@infix = infix
|
@@ -13,8 +13,9 @@ module Rokaki
|
|
13
13
|
@filter_methods = []
|
14
14
|
@filter_templates = []
|
15
15
|
@db = db
|
16
|
+
@mode = mode
|
16
17
|
end
|
17
|
-
attr_reader :filter_key_object, :prefix, :infix, :like_semantics, :i_like_semantics, :db
|
18
|
+
attr_reader :filter_key_object, :prefix, :infix, :like_semantics, :i_like_semantics, :db, :mode
|
18
19
|
attr_accessor :filter_methods, :filter_templates
|
19
20
|
|
20
21
|
def call # _chain_nested_filter
|
@@ -56,7 +57,7 @@ module Rokaki
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def find_i_like_key(keys)
|
59
|
-
return nil unless
|
60
|
+
return nil unless i_like_semantics && i_like_semantics.keys.any?
|
60
61
|
current_like_key = i_like_semantics
|
61
62
|
keys.each do |key|
|
62
63
|
current_like_key = current_like_key[key]
|
data/lib/rokaki/filterable.rb
CHANGED
data/lib/rokaki/version.rb
CHANGED