ruby_simple_search 2.0.0 → 2.0.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
- SHA1:
3
- metadata.gz: fff76b38b0d4b750a205788f0213735da4d14e0e
4
- data.tar.gz: 91d61ad7a53a00f9b818951aff37c2b88c4c8095
2
+ SHA256:
3
+ metadata.gz: 33cda6d4c33aefea4fe48b0270b97ca8ec2f8a2cd2ab5f5e1888b36e5803e46f
4
+ data.tar.gz: c7cdc38d3e5b0ca43732e5197e800628e2bbb3b00274587a628b0c2bfb8d21d8
5
5
  SHA512:
6
- metadata.gz: 0dad0091246f35424bb7a529f2ab8259096074ea5de4e2a0c3c200cde61bcd7c4f0868b10ac19453c2b192bcf25a75bf6af69d63493b18e3e4c10f783ad15187
7
- data.tar.gz: 3e59a4db93d6c3302a8a89cfbe8758c28fbfaf5f59203663a582e479461b20a24dc34632f087821616874ee2fe676bec79979e42ea33d1e28c921935c0efbfbf
6
+ metadata.gz: 6ddba0207e0e1a533a6764e6573e6b205a9b6b4df5279fd9c17af24aabf5a0ca1da0784d701c33ddb93505f3badf6ec58ddb8d05afc6b1e2dd8c8e7d24ad2d99
7
+ data.tar.gz: '08018957ab245bd9a03c08857ed4ab95be8b92ae81e8d5310eff8191cb4576772e018eafe329f4cc0dbfe511d7e7adf44e2e1a912c10455a2b644f6b5344ef0f'
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [2.0.0]
7
+
8
+ ## 2.0.1
9
+ - Supported Rails 6
10
+ - Dropped support Rails < 5
11
+
12
+ ## 2.0.0
8
13
  ### Added
9
14
  - Supports `attributes` parameter to `simple_search` method. [PR#4](https://github.com/mechanicles/ruby_simple_search/pull/4)
10
15
  - Supports data types other than `string` and `text` to `simple_search_attributes`
@@ -18,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
18
23
  ### Removed
19
24
  - Removed `plain` pattern from `LIKE` query
20
25
 
21
- ## [0.0.3]
26
+ ## 0.0.3
22
27
  ### Fixed
23
28
  - Fixed problem when using simple search with joins. [GI#1](https://github.com/mechanicles/ruby_simple_search/issues/1)
24
29
 
@@ -26,13 +31,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
26
31
  - Moved pattern option to `simple_search` method and removed it from `simple_search_attributes` method
27
32
  - Updated specs accordingly
28
33
 
29
- ## [0.0.2]
34
+ ## 0.0.2
30
35
  ### Added
31
36
  - Added support for `LIKE` patterns e.g. 'beginning', 'ending', 'containing', 'underscore', and 'plain'
32
37
  - Added block support to `simple_search` method so user can extend it based on its need
33
38
  - Added specs
34
39
  - Added some exceptions handling
35
40
 
36
- ## [0.0.1]
41
+ ## 0.0.1
37
42
  ### Added
38
43
  - First major release
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # RubySimpleSearch
2
2
 
3
+
4
+ [![Build Status](https://travis-ci.org/mechanicles/ruby_simple_search.svg?branch=master)](https://travis-ci.org/mechanicles/ruby_simple_search)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/20e84a4c3be302b07653/maintainability)](https://codeclimate.com/github/mechanicles/ruby_simple_search/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/20e84a4c3be302b07653/test_coverage)](https://codeclimate.com/github/mechanicles/ruby_simple_search/test_coverage)
7
+
3
8
  The simplest way to search the data in ActiveRecord models.
4
9
 
5
10
  It offers simple but useful features:
@@ -18,8 +23,6 @@ and again on the different models, you add lots of duplication in your code.
18
23
 
19
24
  #### Do not repeat yourself, use RubySimpleSearch.
20
25
 
21
- [![Build Status](https://travis-ci.org/mechanicles/ruby_simple_search.svg?branch=master)](https://travis-ci.org/mechanicles/ruby_simple_search)
22
-
23
26
  ## Installation
24
27
 
25
28
  Add this line to your application's Gemfile:
@@ -1,7 +1,9 @@
1
- require 'ruby_simple_search/version'
2
- require 'ruby_simple_search/like_patterns'
3
- require 'ruby_simple_search/errors'
4
- require 'active_support/concern'
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby_simple_search/version"
4
+ require "ruby_simple_search/like_patterns"
5
+ require "ruby_simple_search/errors"
6
+ require "active_support/concern"
5
7
 
6
8
  module RubySimpleSearch
7
9
  extend ActiveSupport::Concern
@@ -26,90 +28,89 @@ module RubySimpleSearch
26
28
 
27
29
  @simple_search_term = search_term
28
30
  @simple_search_pattern = get_pattern(options[:pattern])
29
- @simple_search_patterned_text = @simple_search_pattern.gsub('q', @simple_search_term.try(:downcase))
30
- @simple_search_query_conditions = ''
31
+ @simple_search_patterned_text = @simple_search_pattern.gsub("q", @simple_search_term.try(:downcase))
32
+ @simple_search_query_conditions = []
31
33
  @simple_search_query_values = []
32
34
 
33
35
  build_query_conditions_and_values(options)
34
36
  extend_query(block) if block.is_a? Proc
35
37
 
36
- sql_query = [@simple_search_query_conditions, @simple_search_query_values]
38
+ sql_query = [@simple_search_query_conditions.join, @simple_search_query_values]
37
39
  where(sql_query.flatten)
38
40
  end
39
41
 
40
42
  private
41
-
42
- def get_pattern(pattern)
43
- if pattern.nil?
44
- # default pattern is '%q%'
45
- LIKE_PATTERNS[:containing]
46
- else
47
- pattern = LIKE_PATTERNS[pattern.to_sym]
48
- raise Errors::INVALID_PATTERN if pattern.nil?
49
-
50
- pattern
43
+ def get_pattern(pattern)
44
+ if pattern.nil?
45
+ # default pattern is '%q%'
46
+ LIKE_PATTERNS[:containing]
47
+ else
48
+ pattern = LIKE_PATTERNS[pattern.to_sym]
49
+ raise Errors::INVALID_PATTERN if pattern.nil?
50
+
51
+ pattern
52
+ end
51
53
  end
52
- end
53
54
 
54
- def build_query_conditions_and_values(options)
55
- attributes = if options[:attributes].nil?
56
- @simple_search_attributes
57
- else
58
- _attr = *options[:attributes]
59
- end
55
+ def build_query_conditions_and_values(options)
56
+ attributes = if options[:attributes].nil?
57
+ @simple_search_attributes
58
+ else
59
+ _attr = *options[:attributes]
60
+ end
60
61
 
61
- attributes.each do |attribute|
62
- condition, value = build_query_condition_and_value(attribute)
62
+ attributes.each do |attribute|
63
+ condition, value = build_query_condition_and_value(attribute)
63
64
 
64
- @simple_search_query_conditions << condition
65
- @simple_search_query_values << value
65
+ @simple_search_query_conditions << condition
66
+ @simple_search_query_values << value
67
+ end
66
68
  end
67
- end
68
69
 
69
- def build_query_condition_and_value(attribute)
70
- condition = if %i[string text].include?(columns_hash[attribute.to_s].type)
71
- build_query_for_string_and_text_types(attribute)
72
- else
73
- build_query_non_string_and_text_types(attribute)
74
- end
70
+ def build_query_condition_and_value(attribute)
71
+ condition = if %i[string text].include?(columns_hash[attribute.to_s].type)
72
+ build_query_for_string_and_text_types(attribute)
73
+ else
74
+ build_query_non_string_and_text_types(attribute)
75
+ end
75
76
 
76
- [condition, @simple_search_patterned_text]
77
- end
77
+ [condition, @simple_search_patterned_text]
78
+ end
78
79
 
79
- def build_query_for_string_and_text_types(attribute)
80
- if @simple_search_query_conditions.blank?
81
- "LOWER(#{table_name}.#{attribute}) LIKE ?"
82
- else
83
- " OR LOWER(#{table_name}.#{attribute}) LIKE ?"
80
+ def build_query_for_string_and_text_types(attribute)
81
+ if @simple_search_query_conditions.blank?
82
+ "LOWER(#{table_name}.#{attribute}) LIKE ?"
83
+ else
84
+ " OR LOWER(#{table_name}.#{attribute}) LIKE ?"
85
+ end
84
86
  end
85
- end
86
87
 
87
- def build_query_non_string_and_text_types(attribute)
88
- if @simple_search_query_conditions.blank?
89
- "CAST(#{table_name}.#{attribute} AS CHAR(255)) LIKE ?"
90
- else
91
- " OR CAST(#{table_name}.#{attribute} AS CHAR(255)) LIKE ?"
88
+ def build_query_non_string_and_text_types(attribute)
89
+ if @simple_search_query_conditions.blank?
90
+ "CAST(#{table_name}.#{attribute} AS CHAR(255)) LIKE ?"
91
+ else
92
+ " OR CAST(#{table_name}.#{attribute} AS CHAR(255)) LIKE ?"
93
+ end
92
94
  end
93
- end
94
95
 
95
- def extend_query(block)
96
- @simple_search_query_conditions = "(#{@simple_search_query_conditions})"
97
- extended_query = block.call @simple_search_term
98
- extend_simple_search(extended_query) if extended_query
99
- end
96
+ def extend_query(block)
97
+ @simple_search_query_conditions = ["(#{@simple_search_query_conditions.join})"]
98
+ extended_query = block.call @simple_search_term
99
+ extend_simple_search(extended_query) if extended_query
100
+ end
100
101
 
101
- def extend_simple_search(extended_query)
102
- raise Errors::INVALID_TYPE unless extended_query.is_a?(Array)
102
+ def extend_simple_search(extended_query)
103
+ raise Errors::INVALID_TYPE unless extended_query.is_a?(Array)
103
104
 
104
- extended_query_condition = extended_query[0]
105
- extended_query_values = extended_query - [extended_query[0]]
105
+ extended_query_condition = extended_query[0]
106
+ extended_query_values = extended_query - [extended_query[0]]
106
107
 
107
- if extended_query_condition.count('?') != extended_query_values.size
108
- raise Errors::INVALID_CONDITION
109
- end
108
+ if extended_query_condition.count("?") != extended_query_values.size
109
+ raise Errors::INVALID_CONDITION
110
+ end
110
111
 
111
- @simple_search_query_conditions << " #{extended_query_condition}"
112
- @simple_search_query_values += extended_query_values
113
- end
112
+ @simple_search_query_conditions << " #{extended_query_condition}"
113
+ @simple_search_query_values += extended_query_values
114
+ end
114
115
  end
115
116
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubySimpleSearch
2
4
  module Errors
3
- ATTRIBUTES_MISSING = 'Simple search attributes are missing'.freeze
4
- INVALID_CONDITION = "Extended query's array conditions are wrong".freeze
5
- INVALID_TYPE = 'Extended query is not an array type'.freeze
6
- INVALID_PATTERN = "Looks like given pattern is wrong, valid pattern list is '#{LIKE_PATTERNS.keys}'".freeze
7
- SEARCH_ARG_TYPE = '`search_term` argument is not a string'.freeze
8
- WRONG_ATTRIBUTES = "`simple_search_arguments` method's arguments should be in symbol format".freeze
5
+ ATTRIBUTES_MISSING = "Simple search attributes are missing"
6
+ INVALID_CONDITION = "Extended query's array conditions are wrong"
7
+ INVALID_TYPE = "Extended query is not an array type"
8
+ INVALID_PATTERN = "Looks like given pattern is wrong, valid pattern list is '#{LIKE_PATTERNS.keys}'"
9
+ SEARCH_ARG_TYPE = "`search_term` argument is not a string"
10
+ WRONG_ATTRIBUTES = "`simple_search_arguments` method's arguments should be in symbol format"
9
11
  end
10
12
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubySimpleSearch
2
4
  LIKE_PATTERNS = {
3
- plain: 'q',
4
- beginning: 'q%',
5
- ending: '%q',
6
- containing: '%q%'
7
- }.freeze
5
+ plain: "q",
6
+ beginning: "q%",
7
+ ending: "%q",
8
+ containing: "%q%"
9
+ }
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubySimpleSearch
2
- VERSION = '2.0.0'
4
+ VERSION = "2.0.1"
3
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_simple_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santosh Wadghule
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activerecord
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -154,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
168
  - !ruby/object:Gem::Version
155
169
  version: '0'
156
170
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.4.5.1
171
+ rubygems_version: 3.1.2
159
172
  signing_key:
160
173
  specification_version: 4
161
174
  summary: The simplest way to search the data