arel-is-blank 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c442c9cfac67f5cdc45310e68d16b773abb5dda9
4
+ data.tar.gz: 8cf1650fbb9544e90c436d9793e52f10620eb8c1
5
+ SHA512:
6
+ metadata.gz: 2fb34c4388285d49e8a6c353b2a999e986d6332605d4a5f3fe0ef6f0f34f53656a0349cbd969368d37c5598bdf20e078ee77bb67ef999a1f716fb25999f60c76
7
+ data.tar.gz: 0d8246957c8bf064b29c3cd4d1c34bc9879883246405d7344392b4246ba5d24cf63303b6cf23d875d2b3c7dc78577db4ae8039ebce5ebe39351f0ce075e7c1ef
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ .ruby-version
4
+ pkg/
5
+ tmp/
6
+ /.idea/
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.4.0
5
+
6
+ cache: bundler
7
+
8
+ gemfile:
9
+ - gemfiles/arel_6.x.gemfile
10
+ - gemfiles/arel_8.x.gemfile
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ appraise 'arel-6.x' do
5
+ gem 'arel', '~> 6.0'
6
+ end
7
+
8
+ appraise 'arel-8.x' do
9
+ gem 'arel', '~> 8.0'
10
+ end
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arel-is-blank (1.0.0)
5
+ arel (>= 6.0)
6
+ arel-to-sql (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.1.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ arel (8.0.0)
16
+ arel-to-sql (1.0.0)
17
+ arel (>= 6.0)
18
+ power_assert (1.0.1)
19
+ rake (12.0.0)
20
+ test-unit (3.2.3)
21
+ power_assert
22
+ thor (0.19.4)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ appraisal (~> 2.1)
29
+ arel-is-blank!
30
+ bundler (~> 1.7)
31
+ rake (~> 12.0)
32
+ test-unit (~> 3.2)
33
+
34
+ BUNDLED WITH
35
+ 1.14.3
@@ -0,0 +1,37 @@
1
+ ## Adds several methods which help to build conditions around value presence.
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/arel-is-blank.svg)](https://badge.fury.io/rb/arel-is-blank)
4
+ [![Build Status](https://travis-ci.org/yivo/arel-is-blank.svg?branch=master)](https://travis-ci.org/yivo/arel-is-blank)
5
+
6
+ ## About
7
+ `Àrel::Attributes::Attribute` receives several methods which help to build conditions around value presence.
8
+
9
+ ## Usage
10
+ ```ruby
11
+ # Get posts with detailed description.
12
+ t = Post.arel_table
13
+ posts = Post.where(t[:detailed_description].is_not_blank)
14
+ # SELECT * FROM `posts` WHERE (`posts`.`detailed_description` IS NOT NULL AND `posts`.`detailed_description` <> '')
15
+ ```
16
+
17
+ ## Installing gem
18
+ Add to your Gemfile:
19
+ ```ruby
20
+ gem 'arel-is-blank', '~> 1.0'
21
+ ```
22
+
23
+ ## Running Tests
24
+ Install bundler:
25
+ ```bash
26
+ gem install bundler
27
+ ```
28
+
29
+ Install dependencies:
30
+ ```bash
31
+ cd arel-is-blank && bundle
32
+ ```
33
+
34
+ Run tests:
35
+ ```bash
36
+ cd arel-is-blank && appraisal rake test
37
+ ```
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new { |t| t.libs << 'test' }
7
+
8
+ task default: :test
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path('../lib/arel-is-blank/version', __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'arel-is-blank'
8
+ s.version = ArelIsBlank::VERSION
9
+ s.author = 'Yaroslav Konoplov'
10
+ s.email = 'eahome00@gmail.com'
11
+ s.summary = 'Adds is_blank to arel attribute.'
12
+ s.description = 'Adds is_blank to arel attribute.'
13
+ s.homepage = 'https://github.com/yivo/arel-is-blank'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'arel', '>= 6.0'
21
+ s.add_dependency 'arel-to-sql', '~> 1.0'
22
+ s.add_development_dependency 'rake', '~> 12.0'
23
+ s.add_development_dependency 'test-unit', '~> 3.2'
24
+ s.add_development_dependency 'bundler', '~> 1.7'
25
+ s.add_development_dependency 'appraisal', '~> 2.1'
26
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "arel", "~> 6.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ arel-is-blank (1.0.0)
5
+ arel (>= 6.0)
6
+ arel-to-sql (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.1.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ arel (6.0.4)
16
+ arel-to-sql (1.0.0)
17
+ arel (>= 6.0)
18
+ power_assert (1.0.1)
19
+ rake (12.0.0)
20
+ test-unit (3.2.3)
21
+ power_assert
22
+ thor (0.19.4)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ appraisal (~> 2.1)
29
+ arel (~> 6.0)
30
+ arel-is-blank!
31
+ bundler (~> 1.7)
32
+ rake (~> 12.0)
33
+ test-unit (~> 3.2)
34
+
35
+ BUNDLED WITH
36
+ 1.14.3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "arel", "~> 8.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ arel-is-blank (1.0.0)
5
+ arel (>= 6.0)
6
+ arel-to-sql (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.1.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ arel (8.0.0)
16
+ arel-to-sql (1.0.0)
17
+ arel (>= 6.0)
18
+ power_assert (1.0.1)
19
+ rake (12.0.0)
20
+ test-unit (3.2.3)
21
+ power_assert
22
+ thor (0.19.4)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ appraisal (~> 2.1)
29
+ arel (~> 8.0)
30
+ arel-is-blank!
31
+ bundler (~> 1.7)
32
+ rake (~> 12.0)
33
+ test-unit (~> 3.2)
34
+
35
+ BUNDLED WITH
36
+ 1.14.3
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module ArelIsBlank
5
+ module Extension
6
+ def is_blank
7
+ "(#{to_sql} IS NULL OR #{to_sql} = '')"
8
+ end
9
+
10
+ def is_not_blank
11
+ "(#{to_sql} IS NOT NULL AND #{to_sql} <> '')"
12
+ end
13
+
14
+ def is_blank_or_equals(value)
15
+ engine = relation.respond_to?(:engine) ? relation.engine : Arel::Table.engine
16
+ "(#{to_sql} = #{engine.connection.quote(value)} OR #{is_blank})"
17
+ end
18
+ end
19
+ end
20
+
21
+ require 'arel'
22
+ require 'arel-to-sql'
23
+
24
+ Arel::Attributes::Attribute.include ArelIsBlank::Extension
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module ArelIsBlank
5
+ VERSION = '1.0.0'
6
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler'
5
+ Bundler.require :default, :development, :test
6
+
7
+ class FakeRecord
8
+ class Connection
9
+ def quote_table_name(name)
10
+ "`#{name}`"
11
+ end
12
+
13
+ def quote_column_name(name)
14
+ "`#{name}`"
15
+ end
16
+
17
+ def quote(value)
18
+ String === value ? "'#{value}'" : value
19
+ end
20
+ end
21
+
22
+ class << self
23
+ attr_accessor :connection
24
+ end
25
+
26
+ self.connection = Connection.new
27
+ end
28
+
29
+ class ArelToSQLTest < Test::Unit::TestCase
30
+ def test_is_blank
31
+ table = Arel::Table.new(:users)
32
+ assert_equal "(`users`.`name` IS NULL OR `users`.`name` = '')", table[:name].is_blank
33
+ end
34
+
35
+ def test_is_blank_or_equals
36
+ table = Arel::Table.new(:users)
37
+ assert_equal "(`users`.`name` = 'Anonymous' OR (`users`.`name` IS NULL OR `users`.`name` = ''))",
38
+ table[:name].is_blank_or_equals('Anonymous')
39
+ end
40
+
41
+ def setup
42
+ super
43
+ Arel::Table.engine = FakeRecord
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arel-is-blank
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: arel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: arel-to-sql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ description: Adds is_blank to arel attribute.
98
+ email: eahome00@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".travis.yml"
105
+ - Appraisals
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - README.md
109
+ - Rakefile
110
+ - arel-is-blank.gemspec
111
+ - gemfiles/arel_6.x.gemfile
112
+ - gemfiles/arel_6.x.gemfile.lock
113
+ - gemfiles/arel_8.x.gemfile
114
+ - gemfiles/arel_8.x.gemfile.lock
115
+ - lib/arel-is-blank.rb
116
+ - lib/arel-is-blank/version.rb
117
+ - test/test-arel-is-blank.rb
118
+ homepage: https://github.com/yivo/arel-is-blank
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.6.8
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Adds is_blank to arel attribute.
142
+ test_files:
143
+ - test/test-arel-is-blank.rb