create_custom_attributes 0.5.17 → 0.5.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da291bc2e4b77983c12426a2c6b6b9f0aaeb55b3
4
- data.tar.gz: d60409a040c85fa5f876adf99f5df1d1213527a4
3
+ metadata.gz: 37f1043bf4b471386ce78c80bd9945beef5d780e
4
+ data.tar.gz: c07398c5b2b32eb27829797600f8d1709653ae69
5
5
  SHA512:
6
- metadata.gz: b97b5f9be626f258af322b2cc0e2689df04db66e753cbe93c69069cec151876d596e5691e0d56d39d55959185346ede2bd8e5c9aaf75605e59348c8ac02b3d39
7
- data.tar.gz: 505ccd757de9304aa6b2f511bee09a892edb66c90903a015f023060f2e9de1a0d586f0f62e47ff04ffee2cf6540eafa36a0481d6adceb48a6d18c07b82110c97
6
+ metadata.gz: 2751ba3366b7596c9e3b3fe9aa8239d8db42202d5cef8296b7185c58ca86b4052fdd8e85e8cf5d9612ef54836f63dbd9f9e7c92b2d158941e66ab1e2d09d094e
7
+ data.tar.gz: fb4755ef8823a48ee88af2a1c7abc27fc94b92701ea73e75724b04511975734804150859754fec8d4b48dafdad48529cbe71b6f9d23e434bdc3187d18902fc9f
@@ -51,6 +51,18 @@ module CustomAttributes
51
51
  self
52
52
  end
53
53
 
54
+ def filter_by_delimiter(string)
55
+ @search_query.filter_by_delimiter = string
56
+
57
+ self
58
+ end
59
+
60
+ def filter_or_delimiter(string)
61
+ @search_query.filter_or_delimiter = string
62
+
63
+ self
64
+ end
65
+
54
66
  def sort_by(field_list)
55
67
  @search_query.sort_by.merge! field_list
56
68
 
@@ -3,7 +3,7 @@ require 'custom_attributes/search_query_field'
3
3
  module CustomAttributes
4
4
  # Builds a query in elastic search DSL
5
5
  class SearchQuery
6
- attr_accessor :customizable, :query, :field_list, :defaults, :sort_by, :page, :per_page, :match_any, :filter_by, :filter_or
6
+ attr_accessor :customizable, :query, :field_list, :defaults, :sort_by, :page, :per_page, :match_any, :filter_by, :filter_or, :filter_by_delimiter, :filter_or_delimiter
7
7
 
8
8
  def build
9
9
  {
@@ -39,6 +39,14 @@ module CustomAttributes
39
39
  @filter_or ||= {}
40
40
  end
41
41
 
42
+ def filter_by_delimiter
43
+ @filter_by_delimiter ||= {}
44
+ end
45
+
46
+ def filter_or_delimiter
47
+ @filter_or_delimiter ||= {}
48
+ end
49
+
42
50
  def sort_by
43
51
  @sort_by ||= {}
44
52
  end
@@ -161,8 +169,10 @@ module CustomAttributes
161
169
  end
162
170
  end
163
171
 
164
- def filter_hash_to_term_array(filter_list)
172
+ def filter_hash_to_term_array(filter_list, delimiter = '')
165
173
  hash_to_array(filter_list) do |type, field_slug, field_data|
174
+ field_data = field_data.split(delimiter).map(&:strip) if !delimiter.empty? && !field_data.is_a?(Array)
175
+
166
176
  if type == :custom_fields
167
177
  if field_data.is_a? Array
168
178
  field_data.map { |fd| custom_query_scaffold(fd, field_slug, true) }
@@ -182,8 +192,8 @@ module CustomAttributes
182
192
  return filter_hash_to_term_array(filter_by) if filter_or.empty?
183
193
 
184
194
  filter_hash = { minimum_should_match: 1 }
185
- filter_hash[:must] = filter_hash_to_term_array(filter_by) unless filter_by.empty?
186
- filter_hash[:should] = filter_hash_to_term_array(filter_or) unless filter_or.empty?
195
+ filter_hash[:must] = filter_hash_to_term_array(filter_by, filter_by_delimiter) unless filter_by.empty?
196
+ filter_hash[:should] = filter_hash_to_term_array(filter_or, filter_or_delimiter) unless filter_or.empty?
187
197
 
188
198
  [{
189
199
  bool: filter_hash
@@ -1,3 +1,3 @@
1
1
  module CustomAttributes
2
- VERSION = '0.5.17'.freeze
2
+ VERSION = '0.5.18'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create_custom_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.17
4
+ version: 0.5.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Grützmacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails