where_unless_blank 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gempush.yml +29 -0
- data/.gitignore +1 -1
- data/README.md +11 -3
- data/lib/where_unless_blank.rb +14 -0
- data/lib/where_unless_blank/version.rb +1 -1
- data/where_unless_blank.gemspec +3 -2
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dacccda1ad0687f06402acfa2b749005118bded1288cb5951600beeee365a0fc
|
4
|
+
data.tar.gz: e59bb065d7e883e2347d7e0e60c8f50dde650c4eae6f4dc9dcf4c19936ae0544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 027b918e0e3b766174ba3304a2fc59417966af4411adbc5ee3c24547db6e2901c53e11ac69064ddd3ed32495d1021686468c05b6e8b99628f0be4f7f3d5f32ce
|
7
|
+
data.tar.gz: 01f45b1170b512195d4672e5639ef9042d543c42916e8c7259df3d51885feef54e76500062ad89d8cb6d36e11a92a21ab1529e2006b7f25aa22313a883c871b0
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- '*'
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
version: 2.6.x
|
19
|
+
|
20
|
+
- name: Publish to RubyGems
|
21
|
+
run: |
|
22
|
+
mkdir -p $HOME/.gem
|
23
|
+
touch $HOME/.gem/credentials
|
24
|
+
chmod 0600 $HOME/.gem/credentials
|
25
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
26
|
+
gem build *.gemspec
|
27
|
+
gem push *.gem
|
28
|
+
env:
|
29
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# WhereUnlessBlank
|
2
2
|
|
3
|
-
The
|
3
|
+
The behavior of "where" when querrying for a null value is include the statment and return rows with null value.
|
4
4
|
|
5
|
-
This gem
|
5
|
+
This gem creates a simple way to remove statements with null/blank values from query.
|
6
6
|
|
7
7
|
Very usefull for search forms avoiding you to worry about unfilled fields.
|
8
8
|
|
@@ -33,9 +33,17 @@ Person.ilike_unless_blank(name: params[:name], surname: params[:surname])
|
|
33
33
|
Person.like_unless_blank(name: params[:name], surname: params[:surname])
|
34
34
|
```
|
35
35
|
|
36
|
+
If u like short names u can use:
|
37
|
+
|
38
|
+
`wub` or `where_ub` for `where_unless_blank`
|
39
|
+
|
40
|
+
`iub` or `ilike_ub` for `ilike_unless_blank`
|
41
|
+
|
42
|
+
`lub` or `like_ub` for `like_unless_blank`
|
43
|
+
|
36
44
|
If all params are blank it will behaivor like `all` method.
|
37
45
|
|
38
46
|
|
39
47
|
## Contributing
|
40
48
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/platbr/where_unless_blank.
|
data/lib/where_unless_blank.rb
CHANGED
@@ -4,20 +4,34 @@ require "where_unless_blank/engine"
|
|
4
4
|
module WhereUnlessBlank
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
included do
|
7
|
+
|
7
8
|
def self.where_unless_blank(opts = :chain)
|
8
9
|
opts.delete_if {|k,v| v.blank? } if opts.kind_of?(Hash)
|
9
10
|
where(opts)
|
10
11
|
end
|
12
|
+
|
11
13
|
def self.ilike_unless_blank(opts = :chain)
|
12
14
|
operator_unless_blank(opts, 'ilike', '%', '%')
|
13
15
|
end
|
16
|
+
|
14
17
|
def self.like_unless_blank(opts = :chain)
|
15
18
|
operator_unless_blank(opts, 'like', '%', '%')
|
16
19
|
end
|
20
|
+
|
17
21
|
def self.operator_unless_blank(opts, operator = '=', prefix = '', sufix = '')
|
18
22
|
where(WhereUnlessBlank.build_opts(opts, operator, prefix, sufix))
|
19
23
|
end
|
24
|
+
|
25
|
+
class <<self
|
26
|
+
alias_method :wub, :where_unless_blank
|
27
|
+
alias_method :where_ub, :where_unless_blank
|
28
|
+
alias_method :iub, :ilike_unless_blank
|
29
|
+
alias_method :ilike_ub, :ilike_unless_blank
|
30
|
+
alias_method :lub, :like_unless_blank
|
31
|
+
alias_method :like_ub, :like_unless_blank
|
32
|
+
end
|
20
33
|
end
|
34
|
+
|
21
35
|
def self.build_opts(opts, operator = '=', prefix='', sufix='')
|
22
36
|
opts.delete_if {|k,v| v.blank? } if opts.kind_of?(Hash)
|
23
37
|
[opts.map{|k,v| "#{k} #{operator} ?"}.join(' AND '), opts.values.map{|v| "#{prefix}#{v}#{sufix}"}].flatten unless opts.blank?
|
data/where_unless_blank.gemspec
CHANGED
@@ -9,9 +9,10 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Wagner Caixeta"]
|
10
10
|
spec.email = ["wagner.caixeta@al.go.leg.br"]
|
11
11
|
|
12
|
-
spec.summary = %q{This gem
|
12
|
+
spec.summary = %q{This gem creates a simple way to remove statements with null/blank values from query.}
|
13
13
|
spec.description = %q{
|
14
|
-
|
14
|
+
The behavior of "where" when querrying for a null value is include the statment and return rows with null value.
|
15
|
+
This gem creates a simple way to remove statements with null/blank values from query.
|
15
16
|
Very usefull for search forms avoiding you to worry about unfilled fields.
|
16
17
|
}
|
17
18
|
spec.homepage = "https://github.com/platbr/where_unless_blank"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: where_unless_blank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wagner Caixeta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,15 +52,17 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: "\n
|
56
|
-
|
57
|
-
|
55
|
+
description: "\n The behavior of \"where\" when querrying for a null value is include
|
56
|
+
the statment and return rows with null value.\n This gem creates a simple way
|
57
|
+
to remove statements with null/blank values from query.\n Very usefull for search
|
58
|
+
forms avoiding you to worry about unfilled fields.\n "
|
58
59
|
email:
|
59
60
|
- wagner.caixeta@al.go.leg.br
|
60
61
|
executables: []
|
61
62
|
extensions: []
|
62
63
|
extra_rdoc_files: []
|
63
64
|
files:
|
65
|
+
- ".github/workflows/gempush.yml"
|
64
66
|
- ".gitignore"
|
65
67
|
- Gemfile
|
66
68
|
- LICENSE
|
@@ -90,8 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
- !ruby/object:Gem::Version
|
91
93
|
version: '0'
|
92
94
|
requirements: []
|
93
|
-
rubygems_version: 3.0.
|
95
|
+
rubygems_version: 3.0.3
|
94
96
|
signing_key:
|
95
97
|
specification_version: 4
|
96
|
-
summary: This gem
|
98
|
+
summary: This gem creates a simple way to remove statements with null/blank values
|
99
|
+
from query.
|
97
100
|
test_files: []
|