like_query 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: 0cb474c6c4f84bd5197241f8aba6fba22a65e8eb186b390eb62ed92ebb1c6900
4
- data.tar.gz: 573d9725dd2467394fbfaf7ac8ddc0ad85fae5e6461f10f23df83f9471811a6c
3
+ metadata.gz: 4acb76ba7e99c858ec318cb2f52d82e3c063d53941775c5b18d34cb084f8d624
4
+ data.tar.gz: 619ed012558607d25ef0bef7766a96b5ee1ec9923185d6ff7c4dfda0a62ee08c
5
5
  SHA512:
6
- metadata.gz: dfe938db839e0a98b4a086cd8c9ef22db27f5d752ddf8749b93a4144a75ea1a9ea7c1a3b77900077fee92cd7293082083d567cbaa223bf143f3216cc6dfae2b0
7
- data.tar.gz: b9ba846502a4a31f3b53565679b7d7befe2c59978c362099cf03b242087f5dba3daeeb4ad9d4f6393acbfeaa13afc0dfaf153057732982e441ff23beb8822845
6
+ metadata.gz: 5846f20fa64023168c9f4468dadb90aa5f73ea131b63eae29e6ad9b06b750d4e5b9d38cd670accdad72be12eb2940a4af11dfac96c865fda0c7cfcc3ccc71aad
7
+ data.tar.gz: 66c59b0de6ebaa45fe6d237561c88a6e266575dade903dacbd6880df001cc4f172631a26040e9a7322f227f6bee1d787b300d8e9d2e19abb44211dd2d4510e8e
data/README.md CHANGED
@@ -106,6 +106,25 @@ Book.like('Nelson 3.4..8', [:title, :price])
106
106
  # => find books where title includes "Nelson" and price (must be number column) is between 3.4 and 8
107
107
  ```
108
108
 
109
+ **Column specific search**
110
+
111
+ ```ruby
112
+ Book.like('title:history', [:title, :price])
113
+ # => find books where title includes "history"
114
+
115
+ Book.like('author.name:marc', [{author: [:name]}])
116
+ # => find books where author.name includes "marc"
117
+ ```
118
+
119
+ There is a helper for allowing the user translating the column names:
120
+
121
+ ```ruby
122
+ LikeQuery::Formatter.translate_columns('one N:two', [['n','name']], case_sensitive: false)
123
+ # => 'one name:two'
124
+ # case_sensitive: Default is true
125
+ ```
126
+ Only upper and lower chars (if case-insensitive), point, underscore, and no German-Umlaute are allowed on the column-key
127
+
109
128
  **Class LikeQuery::Collect**
110
129
 
111
130
  ```ruby
@@ -9,7 +9,7 @@ module LikeQuery
9
9
  def self.translate_columns(search_string, column_translations, case_sensitive: true)
10
10
  search_string.split(' ').map do |str|
11
11
 
12
- reg = (case_sensitive ? /^[a-z_]+(?=:)/ : /^[a-zA-Z_]+(?=:)/)
12
+ reg = (case_sensitive ? /^[a-z_\.]+(?=:)/ : /^[a-zA-Z_\.]+(?=:)/)
13
13
 
14
14
  column = if case_sensitive
15
15
  str.match(reg)
@@ -55,7 +55,8 @@ module LikeQuery
55
55
 
56
56
  end
57
57
 
58
- queries.push("(#{q.compact.join(' OR ')})")
58
+ __q = q.compact
59
+ queries.push("(#{__q.join(' OR ')})") if __q.present?
59
60
  end
60
61
 
61
62
  if associations.present?
@@ -100,7 +101,7 @@ module LikeQuery
100
101
 
101
102
  def format_string_element(str)
102
103
 
103
- column = str.match(/^[a-z_]+(?=:)/)
104
+ column = str.match(/^[a-z_\.]+(?=:)/)
104
105
  _str = (column ? str.match(/(?<=:)[\s\S]+/) : str).to_s
105
106
  match_number = _str.match(/^(\d+(?:\.\d+)?)$/)
106
107
  match_range = _str.match(/^(\d+(?:\.\d+)?)(\.\.)(\d+(?:\.\d+)?)$/)
@@ -121,7 +122,7 @@ module LikeQuery
121
122
  {}
122
123
  end
123
124
  res[:string] = _str
124
- res[:column] = column.to_s.to_sym if column
125
+ res[:column] = column.to_s if column
125
126
  res
126
127
  end
127
128
 
@@ -135,7 +136,9 @@ module LikeQuery
135
136
  end
136
137
  arel = base_object.arel_table[schema_column]
137
138
 
138
- if !search_string[:column] || schema_column == search_string[:column]
139
+ col = (association ? [association.name, schema_column.to_s].join('.') : schema_column.to_s)
140
+
141
+ if !search_string[:column] || col == search_string[:column]
139
142
  if search_string[:float_from] && [:float, :decimal, :big_decimal, :integer, :bigint].include?(type)
140
143
 
141
144
  q = arel.between(search_string[:float_from]..search_string[:float_until]).to_sql
@@ -1,3 +1,3 @@
1
1
  module LikeQuery
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: like_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian