rokaki 0.8.0.pre.pre → 0.8.2

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: cd7982d23aa428243393be242a44e66655f3805cd23e2cb75e9f9ac1d9f6e8a3
4
- data.tar.gz: 07d183020e8234b19d253cbde9172a3d802a705be0e535d982c6be06087ab3a5
3
+ metadata.gz: b5484d6a4935bbc4f908e9081c82fcfd757f2e49770b7cbde2c055ec9ab169b0
4
+ data.tar.gz: 44a41e6c4ba814bc98934ddb2029a222841fd18425847c73ab3a9a3d86acc66a
5
5
  SHA512:
6
- metadata.gz: 8a22d6928e09c881f021e16b92bffa57f43f8a872528ab49f1b25f5ffc0c0a5918898944ea41439ed58d5e1fa1a40fbc16cbc6fa628f7380680cc2cc1bc3abe2
7
- data.tar.gz: 8e9ac460a085d3bc32b72cb9b9d1c6198da65bae3e6d76a03a916708faa2e5862c3102d66407b795c23c93e4b527ea5fbda190d93ae876a583253d8b18d08ce7
6
+ metadata.gz: e8c29246d64a0fc0c5ca63173c419cee77cf07cd06d99a1fc14bcc53285222d980e8ace9e624bb75d4566814bfc8ce38613305676d2152591da83f8ea04002b1
7
+ data.tar.gz: 82ac3f4b16473b8adf6aeeb93907a0e71ab811c439d5071e95b063238042828c39818f33763a953fa0898c40c0d0f912cc6b3781b9ff1bb75d6c3227c8efd282
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  tags
13
+ *.gem
@@ -1,32 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rokaki (0.7.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.0)
11
- activesupport (= 6.0.0)
12
- activerecord (6.0.0)
13
- activemodel (= 6.0.0)
14
- activesupport (= 6.0.0)
15
- activesupport (6.0.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.1, >= 2.1.8)
21
- byebug (11.0.1)
22
- coderay (1.1.2)
23
- concurrent-ruby (1.1.5)
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 (5.1.1)
26
- activesupport (>= 4.2.0)
27
- ffi (1.11.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.15.0)
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.6.0)
43
+ i18n (1.8.3)
44
44
  concurrent-ruby (~> 1.0)
45
- listen (3.1.5)
46
- rb-fsevent (~> 0.9, >= 0.9.4)
47
- rb-inotify (~> 0.9, >= 0.9.7)
48
- ruby_dep (~> 1.2)
49
- lumberjack (1.0.13)
50
- method_source (0.9.2)
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.1.4)
57
- pry (0.12.2)
58
- coderay (~> 1.1.0)
59
- method_source (~> 0.9.0)
60
- pry-byebug (3.7.0)
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.10)
63
- rake (10.5.0)
64
- rb-fsevent (0.10.3)
65
- rb-inotify (0.10.0)
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.8.0)
68
- rspec-core (~> 3.8.0)
69
- rspec-expectations (~> 3.8.0)
70
- rspec-mocks (~> 3.8.0)
71
- rspec-core (3.8.2)
72
- rspec-support (~> 3.8.0)
73
- rspec-expectations (3.8.4)
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.8.0)
76
- rspec-mocks (3.8.1)
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.8.0)
79
- rspec-support (3.8.2)
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.1)
83
- thor (0.20.3)
80
+ sqlite3 (1.4.2)
81
+ thor (1.0.1)
84
82
  thread_safe (0.3.6)
85
- tzinfo (1.2.5)
83
+ tzinfo (1.2.7)
86
84
  thread_safe (~> 0.1)
87
- zeitwerk (2.1.9)
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 (~> 10.0)
99
+ rake (~> 13.0)
102
100
  rokaki!
103
101
  rspec (~> 3.0)
104
102
  sqlite3
105
103
 
106
104
  BUNDLED WITH
107
- 2.1.3
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 porcelain command syntax
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
 
@@ -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
- define_filter_keys(*filter_keys)
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
- @model.reflect_on_association(association).klass.table_name
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
- like_keys << map_keys(args[key], key)
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
- key_result[key] = map_keys(sub_value, sub_key)
43
+ map_keys(sub_value, sub_key, key_path)
42
44
  end
43
45
  end
44
46
  else
45
- key_result = key
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 like_semantics && i_like_semantics.keys.any?
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]
@@ -23,6 +23,10 @@ module Rokaki
23
23
  end
24
24
  end
25
25
 
26
+ def define_query_key(key = nil)
27
+ @filter_map_query_key = key
28
+ end
29
+
26
30
  def filter_key_prefix(prefix = nil)
27
31
  @filter_key_prefix ||= prefix
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module Rokaki
2
- VERSION = "0.8.0-pre"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -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', '~> 10.0'
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.0.pre.pre
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-04-10 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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: 1.3.1
227
+ version: '0'
228
228
  requirements: []
229
229
  rubygems_version: 3.1.2
230
230
  signing_key: