rokaki 0.8.0.pre.pre → 0.8.2
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/.gitignore +1 -0
- data/Gemfile.lock +48 -50
- data/README.md +38 -1
- data/lib/rokaki/filter_model.rb +19 -4
- data/lib/rokaki/filter_model/like_keys.rb +13 -4
- data/lib/rokaki/filter_model/nested_filter.rb +1 -1
- data/lib/rokaki/filterable.rb +4 -0
- data/lib/rokaki/version.rb +1 -1
- data/rokaki.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5484d6a4935bbc4f908e9081c82fcfd757f2e49770b7cbde2c055ec9ab169b0
|
|
4
|
+
data.tar.gz: 44a41e6c4ba814bc98934ddb2029a222841fd18425847c73ab3a9a3d86acc66a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8c29246d64a0fc0c5ca63173c419cee77cf07cd06d99a1fc14bcc53285222d980e8ace9e624bb75d4566814bfc8ce38613305676d2152591da83f8ea04002b1
|
|
7
|
+
data.tar.gz: 82ac3f4b16473b8adf6aeeb93907a0e71ab811c439d5071e95b063238042828c39818f33763a953fa0898c40c0d0f912cc6b3781b9ff1bb75d6c3227c8efd282
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rokaki (0.
|
|
4
|
+
rokaki (0.8.2)
|
|
5
5
|
activesupport
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activemodel (6.0.
|
|
11
|
-
activesupport (= 6.0.
|
|
12
|
-
activerecord (6.0.
|
|
13
|
-
activemodel (= 6.0.
|
|
14
|
-
activesupport (= 6.0.
|
|
15
|
-
activesupport (6.0.
|
|
10
|
+
activemodel (6.0.3.2)
|
|
11
|
+
activesupport (= 6.0.3.2)
|
|
12
|
+
activerecord (6.0.3.2)
|
|
13
|
+
activemodel (= 6.0.3.2)
|
|
14
|
+
activesupport (= 6.0.3.2)
|
|
15
|
+
activesupport (6.0.3.2)
|
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
17
|
i18n (>= 0.7, < 2)
|
|
18
18
|
minitest (~> 5.1)
|
|
19
19
|
tzinfo (~> 1.1)
|
|
20
|
-
zeitwerk (~> 2.
|
|
21
|
-
byebug (11.
|
|
22
|
-
coderay (1.1.
|
|
23
|
-
concurrent-ruby (1.1.
|
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
21
|
+
byebug (11.1.3)
|
|
22
|
+
coderay (1.1.3)
|
|
23
|
+
concurrent-ruby (1.1.6)
|
|
24
24
|
diff-lcs (1.3)
|
|
25
|
-
factory_bot (
|
|
26
|
-
activesupport (>=
|
|
27
|
-
ffi (1.
|
|
25
|
+
factory_bot (6.0.2)
|
|
26
|
+
activesupport (>= 5.0.0)
|
|
27
|
+
ffi (1.13.1)
|
|
28
28
|
formatador (0.2.5)
|
|
29
|
-
guard (2.
|
|
29
|
+
guard (2.16.2)
|
|
30
30
|
formatador (>= 0.2.4)
|
|
31
31
|
listen (>= 2.7, < 4.0)
|
|
32
32
|
lumberjack (>= 1.0.12, < 2.0)
|
|
@@ -40,51 +40,49 @@ GEM
|
|
|
40
40
|
guard (~> 2.1)
|
|
41
41
|
guard-compat (~> 1.1)
|
|
42
42
|
rspec (>= 2.99.0, < 4.0)
|
|
43
|
-
i18n (1.
|
|
43
|
+
i18n (1.8.3)
|
|
44
44
|
concurrent-ruby (~> 1.0)
|
|
45
|
-
listen (3.1
|
|
46
|
-
rb-fsevent (~> 0.
|
|
47
|
-
rb-inotify (~> 0.9, >= 0.9.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
minitest (5.11.3)
|
|
45
|
+
listen (3.2.1)
|
|
46
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
47
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
48
|
+
lumberjack (1.2.6)
|
|
49
|
+
method_source (1.0.0)
|
|
50
|
+
minitest (5.14.1)
|
|
52
51
|
nenv (0.3.0)
|
|
53
52
|
notiffany (0.1.3)
|
|
54
53
|
nenv (~> 0.1)
|
|
55
54
|
shellany (~> 0.0)
|
|
56
|
-
pg (1.
|
|
57
|
-
pry (0.
|
|
58
|
-
coderay (~> 1.1
|
|
59
|
-
method_source (~>
|
|
60
|
-
pry-byebug (3.
|
|
55
|
+
pg (1.2.3)
|
|
56
|
+
pry (0.13.1)
|
|
57
|
+
coderay (~> 1.1)
|
|
58
|
+
method_source (~> 1.0)
|
|
59
|
+
pry-byebug (3.9.0)
|
|
61
60
|
byebug (~> 11.0)
|
|
62
|
-
pry (~> 0.
|
|
63
|
-
rake (
|
|
64
|
-
rb-fsevent (0.10.
|
|
65
|
-
rb-inotify (0.10.
|
|
61
|
+
pry (~> 0.13.0)
|
|
62
|
+
rake (13.0.1)
|
|
63
|
+
rb-fsevent (0.10.4)
|
|
64
|
+
rb-inotify (0.10.1)
|
|
66
65
|
ffi (~> 1.0)
|
|
67
|
-
rspec (3.
|
|
68
|
-
rspec-core (~> 3.
|
|
69
|
-
rspec-expectations (~> 3.
|
|
70
|
-
rspec-mocks (~> 3.
|
|
71
|
-
rspec-core (3.
|
|
72
|
-
rspec-support (~> 3.
|
|
73
|
-
rspec-expectations (3.
|
|
66
|
+
rspec (3.9.0)
|
|
67
|
+
rspec-core (~> 3.9.0)
|
|
68
|
+
rspec-expectations (~> 3.9.0)
|
|
69
|
+
rspec-mocks (~> 3.9.0)
|
|
70
|
+
rspec-core (3.9.2)
|
|
71
|
+
rspec-support (~> 3.9.3)
|
|
72
|
+
rspec-expectations (3.9.2)
|
|
74
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
75
|
-
rspec-support (~> 3.
|
|
76
|
-
rspec-mocks (3.
|
|
74
|
+
rspec-support (~> 3.9.0)
|
|
75
|
+
rspec-mocks (3.9.1)
|
|
77
76
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
78
|
-
rspec-support (~> 3.
|
|
79
|
-
rspec-support (3.
|
|
80
|
-
ruby_dep (1.5.0)
|
|
77
|
+
rspec-support (~> 3.9.0)
|
|
78
|
+
rspec-support (3.9.3)
|
|
81
79
|
shellany (0.0.1)
|
|
82
|
-
sqlite3 (1.4.
|
|
83
|
-
thor (0.
|
|
80
|
+
sqlite3 (1.4.2)
|
|
81
|
+
thor (1.0.1)
|
|
84
82
|
thread_safe (0.3.6)
|
|
85
|
-
tzinfo (1.2.
|
|
83
|
+
tzinfo (1.2.7)
|
|
86
84
|
thread_safe (~> 0.1)
|
|
87
|
-
zeitwerk (2.
|
|
85
|
+
zeitwerk (2.3.0)
|
|
88
86
|
|
|
89
87
|
PLATFORMS
|
|
90
88
|
ruby
|
|
@@ -98,10 +96,10 @@ DEPENDENCIES
|
|
|
98
96
|
pg
|
|
99
97
|
pry
|
|
100
98
|
pry-byebug
|
|
101
|
-
rake (~>
|
|
99
|
+
rake (~> 13.0)
|
|
102
100
|
rokaki!
|
|
103
101
|
rspec (~> 3.0)
|
|
104
102
|
sqlite3
|
|
105
103
|
|
|
106
104
|
BUNDLED WITH
|
|
107
|
-
2.1.
|
|
105
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -8,6 +8,12 @@ There are two modes of use `Filterable` and `FilterModel` that can be activated
|
|
|
8
8
|
|
|
9
9
|
Add this line to your application's Gemfile:
|
|
10
10
|
|
|
11
|
+
You can install from Rubygems:
|
|
12
|
+
```
|
|
13
|
+
gem 'rokaki'
|
|
14
|
+
```
|
|
15
|
+
Or from github
|
|
16
|
+
|
|
11
17
|
```ruby
|
|
12
18
|
gem 'rokaki', git: 'https://github.com/tevio/rokaki.git'
|
|
13
19
|
```
|
|
@@ -190,7 +196,38 @@ end
|
|
|
190
196
|
```
|
|
191
197
|
Or
|
|
192
198
|
|
|
193
|
-
#### 2. The
|
|
199
|
+
#### 2. The `filter_map` command syntax
|
|
200
|
+
`filter_map` takes the model name, then a single 'query' field and maps it to fields named in the options, this is useful if you want to search for a single value across many different fields or associated tables simultaneously. (builds on `define_filter_map`)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
class AuthorFilter
|
|
205
|
+
include Rokaki::FilterModel
|
|
206
|
+
|
|
207
|
+
filter_map :author, :query,
|
|
208
|
+
like: {
|
|
209
|
+
articles: {
|
|
210
|
+
title: :circumfix,
|
|
211
|
+
reviews: {
|
|
212
|
+
title: :circumfix
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
attr_accessor :filters, :model
|
|
218
|
+
|
|
219
|
+
def initialize(filters:)
|
|
220
|
+
@filters = filters
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
filters = { query: "Jiddu" }
|
|
225
|
+
filtered_authors = AuthorFilter.new(filters: filters).results
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
In the above example we search for authors who have written articles containing the word "Jiddu" in the title that also have reviews containing the sames word in their titles.
|
|
229
|
+
|
|
230
|
+
#### 3. The porcelain command syntax
|
|
194
231
|
|
|
195
232
|
In this syntax you will need to provide three keywords:- `filters`, `like` and `filter_model` if you are not passing in the model type and assigning it to `@model`
|
|
196
233
|
|
data/lib/rokaki/filter_model.rb
CHANGED
|
@@ -25,8 +25,19 @@ module Rokaki
|
|
|
25
25
|
|
|
26
26
|
private
|
|
27
27
|
|
|
28
|
+
def filter_map(model, query_key, options)
|
|
29
|
+
filter_model(model)
|
|
30
|
+
@filter_map_query_key = query_key
|
|
31
|
+
|
|
32
|
+
@_filter_db = options[:db] || :postgres
|
|
33
|
+
like(options[:like]) if options[:like]
|
|
34
|
+
ilike(options[:ilike]) if options[:ilike]
|
|
35
|
+
filters(*options[:match]) if options[:match]
|
|
36
|
+
end
|
|
37
|
+
|
|
28
38
|
def filter(model, options)
|
|
29
39
|
filter_model(model)
|
|
40
|
+
@filter_map_query_key = nil
|
|
30
41
|
|
|
31
42
|
@_filter_db = options[:db] || :postgres
|
|
32
43
|
like(options[:like]) if options[:like]
|
|
@@ -35,7 +46,11 @@ module Rokaki
|
|
|
35
46
|
end
|
|
36
47
|
|
|
37
48
|
def filters(*filter_keys)
|
|
38
|
-
|
|
49
|
+
if @filter_map_query_key
|
|
50
|
+
define_filter_map(@filter_map_query_key, *filter_keys)
|
|
51
|
+
else
|
|
52
|
+
define_filter_keys(*filter_keys)
|
|
53
|
+
end
|
|
39
54
|
|
|
40
55
|
@_chain_filters ||= []
|
|
41
56
|
filter_keys.each do |filter_key|
|
|
@@ -86,9 +101,9 @@ module Rokaki
|
|
|
86
101
|
end
|
|
87
102
|
end
|
|
88
103
|
|
|
89
|
-
def associated_table(association)
|
|
90
|
-
|
|
91
|
-
end
|
|
104
|
+
# def associated_table(association)
|
|
105
|
+
# @model.reflect_on_association(association).klass.table_name
|
|
106
|
+
# end
|
|
92
107
|
|
|
93
108
|
def filter_model(model_class)
|
|
94
109
|
@model = (model_class.is_a?(Class) ? model_class : Object.const_get(model_class.capitalize))
|
|
@@ -16,15 +16,16 @@ module Rokaki
|
|
|
16
16
|
|
|
17
17
|
def call
|
|
18
18
|
args.keys.each do |key|
|
|
19
|
-
|
|
19
|
+
map_keys(args[key], key)
|
|
20
20
|
end
|
|
21
21
|
like_keys
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
private
|
|
25
25
|
|
|
26
|
-
def map_keys(value, key)
|
|
26
|
+
def map_keys(value, key, key_path = [])
|
|
27
27
|
key_result = {}
|
|
28
|
+
key_path << key
|
|
28
29
|
|
|
29
30
|
if value.is_a? Hash
|
|
30
31
|
value.keys.each do |sub_key|
|
|
@@ -35,18 +36,26 @@ module Rokaki
|
|
|
35
36
|
key_result[key] << sub_key
|
|
36
37
|
else
|
|
37
38
|
key_result[key] = [ sub_key ]
|
|
39
|
+
@like_keys << deep_assign(key_path, key_result[key])
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
elsif sub_value.is_a? Hash
|
|
41
|
-
|
|
43
|
+
map_keys(sub_value, sub_key, key_path)
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
else
|
|
45
|
-
|
|
47
|
+
@like_keys = [key]
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
key_result
|
|
49
51
|
end
|
|
52
|
+
|
|
53
|
+
# Many thanks Cary Swoveland
|
|
54
|
+
# https://stackoverflow.com/questions/56634950/ruby-dig-set-assign-values-using-hashdig/56635124
|
|
55
|
+
#
|
|
56
|
+
def deep_assign(keys, value)
|
|
57
|
+
keys[0..-2].reverse_each.reduce ({ keys.last => value }) { |h,key| { key=>h } }
|
|
58
|
+
end
|
|
50
59
|
end
|
|
51
60
|
end
|
|
52
61
|
end
|
|
@@ -56,7 +56,7 @@ module Rokaki
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def find_i_like_key(keys)
|
|
59
|
-
return nil unless
|
|
59
|
+
return nil unless i_like_semantics && i_like_semantics.keys.any?
|
|
60
60
|
current_like_key = i_like_semantics
|
|
61
61
|
keys.each do |key|
|
|
62
62
|
current_like_key = current_like_key[key]
|
data/lib/rokaki/filterable.rb
CHANGED
data/lib/rokaki/version.rb
CHANGED
data/rokaki.gemspec
CHANGED
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
|
40
40
|
spec.add_development_dependency 'pg'
|
|
41
41
|
spec.add_development_dependency 'pry'
|
|
42
42
|
spec.add_development_dependency 'pry-byebug'
|
|
43
|
-
spec.add_development_dependency 'rake', '~>
|
|
43
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
44
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
45
45
|
spec.add_development_dependency 'sqlite3'
|
|
46
46
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rokaki
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Martin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -142,14 +142,14 @@ dependencies:
|
|
|
142
142
|
requirements:
|
|
143
143
|
- - "~>"
|
|
144
144
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
145
|
+
version: '13.0'
|
|
146
146
|
type: :development
|
|
147
147
|
prerelease: false
|
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
|
150
150
|
- - "~>"
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '
|
|
152
|
+
version: '13.0'
|
|
153
153
|
- !ruby/object:Gem::Dependency
|
|
154
154
|
name: rspec
|
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -222,9 +222,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
222
222
|
version: '0'
|
|
223
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
requirements:
|
|
225
|
-
- - "
|
|
225
|
+
- - ">="
|
|
226
226
|
- !ruby/object:Gem::Version
|
|
227
|
-
version:
|
|
227
|
+
version: '0'
|
|
228
228
|
requirements: []
|
|
229
229
|
rubygems_version: 3.1.2
|
|
230
230
|
signing_key:
|