arel_extensions 1.3.2 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +43 -91
  4. data/.gitignore +7 -6
  5. data/.rubocop.yml +62 -1
  6. data/Gemfile +11 -11
  7. data/README.md +1 -1
  8. data/Rakefile +4 -4
  9. data/TODO +0 -1
  10. data/appveyor.yml +73 -0
  11. data/arel_extensions.gemspec +12 -12
  12. data/gemfiles/rails3.gemfile +10 -10
  13. data/gemfiles/rails4.gemfile +14 -14
  14. data/gemfiles/rails5_0.gemfile +13 -13
  15. data/gemfiles/rails5_1_4.gemfile +13 -13
  16. data/gemfiles/rails5_2.gemfile +15 -14
  17. data/gemfiles/rails6.gemfile +13 -12
  18. data/gemfiles/rails6_1.gemfile +13 -12
  19. data/gemfiles/rails7.gemfile +9 -8
  20. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  21. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  22. data/init/mssql.sql +0 -0
  23. data/init/mysql.sql +0 -0
  24. data/init/oracle.sql +0 -0
  25. data/init/postgresql.sql +0 -0
  26. data/init/sqlite.sql +0 -0
  27. data/lib/arel_extensions/attributes.rb +2 -2
  28. data/lib/arel_extensions/boolean_functions.rb +2 -4
  29. data/lib/arel_extensions/common_sql_functions.rb +12 -12
  30. data/lib/arel_extensions/comparators.rb +14 -14
  31. data/lib/arel_extensions/date_duration.rb +7 -7
  32. data/lib/arel_extensions/helpers.rb +19 -16
  33. data/lib/arel_extensions/insert_manager.rb +1 -1
  34. data/lib/arel_extensions/math.rb +44 -31
  35. data/lib/arel_extensions/math_functions.rb +18 -18
  36. data/lib/arel_extensions/nodes/abs.rb +0 -0
  37. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  38. data/lib/arel_extensions/nodes/blank.rb +1 -1
  39. data/lib/arel_extensions/nodes/case.rb +4 -6
  40. data/lib/arel_extensions/nodes/cast.rb +5 -5
  41. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  42. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  43. data/lib/arel_extensions/nodes/coalesce.rb +1 -1
  44. data/lib/arel_extensions/nodes/collate.rb +9 -9
  45. data/lib/arel_extensions/nodes/concat.rb +2 -2
  46. data/lib/arel_extensions/nodes/date_diff.rb +10 -10
  47. data/lib/arel_extensions/nodes/duration.rb +0 -0
  48. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  49. data/lib/arel_extensions/nodes/floor.rb +0 -0
  50. data/lib/arel_extensions/nodes/format.rb +0 -0
  51. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  52. data/lib/arel_extensions/nodes/function.rb +21 -21
  53. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  54. data/lib/arel_extensions/nodes/json.rb +7 -7
  55. data/lib/arel_extensions/nodes/length.rb +0 -0
  56. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  57. data/lib/arel_extensions/nodes/locate.rb +1 -1
  58. data/lib/arel_extensions/nodes/log10.rb +0 -0
  59. data/lib/arel_extensions/nodes/matches.rb +1 -1
  60. data/lib/arel_extensions/nodes/md5.rb +0 -0
  61. data/lib/arel_extensions/nodes/power.rb +0 -0
  62. data/lib/arel_extensions/nodes/rand.rb +0 -0
  63. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  64. data/lib/arel_extensions/nodes/replace.rb +2 -2
  65. data/lib/arel_extensions/nodes/round.rb +0 -0
  66. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  67. data/lib/arel_extensions/nodes/std.rb +0 -0
  68. data/lib/arel_extensions/nodes/substring.rb +1 -1
  69. data/lib/arel_extensions/nodes/sum.rb +0 -0
  70. data/lib/arel_extensions/nodes/then.rb +1 -1
  71. data/lib/arel_extensions/nodes/trim.rb +2 -2
  72. data/lib/arel_extensions/nodes/union.rb +4 -4
  73. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  74. data/lib/arel_extensions/nodes/wday.rb +0 -0
  75. data/lib/arel_extensions/nodes.rb +0 -0
  76. data/lib/arel_extensions/null_functions.rb +0 -0
  77. data/lib/arel_extensions/predications.rb +10 -10
  78. data/lib/arel_extensions/railtie.rb +1 -1
  79. data/lib/arel_extensions/set_functions.rb +3 -3
  80. data/lib/arel_extensions/string_functions.rb +8 -8
  81. data/lib/arel_extensions/tasks.rb +2 -2
  82. data/lib/arel_extensions/version.rb +1 -1
  83. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  84. data/lib/arel_extensions/visitors/ibm_db.rb +20 -20
  85. data/lib/arel_extensions/visitors/mssql.rb +150 -130
  86. data/lib/arel_extensions/visitors/mysql.rb +147 -149
  87. data/lib/arel_extensions/visitors/oracle.rb +141 -135
  88. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  89. data/lib/arel_extensions/visitors/postgresql.rb +147 -139
  90. data/lib/arel_extensions/visitors/sqlite.rb +85 -87
  91. data/lib/arel_extensions/visitors/to_sql.rb +146 -148
  92. data/lib/arel_extensions/visitors.rb +7 -7
  93. data/lib/arel_extensions.rb +56 -32
  94. data/test/arelx_test_helper.rb +14 -13
  95. data/test/database.yml +5 -5
  96. data/test/real_db_test.rb +81 -81
  97. data/test/support/fake_record.rb +2 -2
  98. data/test/test_comparators.rb +5 -5
  99. data/test/visitors/test_bulk_insert_oracle.rb +5 -5
  100. data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
  101. data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
  102. data/test/visitors/test_oracle.rb +14 -14
  103. data/test/visitors/test_to_sql.rb +87 -87
  104. data/test/with_ar/all_agnostic_test.rb +411 -306
  105. data/test/with_ar/insert_agnostic_test.rb +19 -16
  106. data/test/with_ar/test_bulk_sqlite.rb +5 -5
  107. data/test/with_ar/test_math_sqlite.rb +12 -12
  108. data/test/with_ar/test_string_mysql.rb +20 -20
  109. data/test/with_ar/test_string_sqlite.rb +20 -20
  110. data/version_v1.rb +1 -1
  111. data/version_v2.rb +1 -1
  112. metadata +3 -9
  113. data/.travis/oracle/download.js +0 -152
  114. data/.travis/oracle/download.sh +0 -30
  115. data/.travis/oracle/download_ojdbc.js +0 -116
  116. data/.travis/oracle/install.sh +0 -34
  117. data/.travis/setup_accounts.sh +0 -9
  118. data/.travis/sqlite3/extension-functions.sh +0 -6
  119. data/.travis.yml +0 -193
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '5.1.4'
4
4
  gem 'arel', '~> 8'
@@ -8,23 +8,23 @@ group :development, :test do
8
8
  gem 'activemodel', '5.1.4'
9
9
  gem 'activerecord', '5.1.4'
10
10
 
11
- gem "sqlite3", '<= 1.3.13', platforms: [:mri, :mswin, :mingw]
12
- gem "mysql2", '0.4.10', platforms: [:mri, :mswin, :mingw]
13
- gem "pg",'< 1.0.0', platforms: [:mri, :mingw]
11
+ gem 'sqlite3', '<= 1.3.13', platforms: %i[mri mswin mingw]
12
+ gem 'mysql2', '0.4.10', platforms: %i[mri mswin mingw]
13
+ gem 'pg', '< 1.0.0', platforms: %i[mri mingw]
14
14
 
15
- gem "tiny_tds", platforms: [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
16
- # gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
15
+ gem 'tiny_tds', platforms: %i[mri mingw] if RUBY_PLATFORM.match?(/windows/)
16
+ # gem "activerecord-sqlserver-adapter", platforms: [:mri, :mingw]
17
17
 
18
- gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
18
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
19
  gem 'activerecord-oracle_enhanced-adapter', '~> 1.8' if ENV.has_key? 'ORACLE_HOME'
20
20
 
21
21
  # for JRuby
22
22
  gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v51.0', platforms: :jruby
23
- gem "jdbc-sqlite3", platforms: :jruby
24
- gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
25
- gem "activerecord-jdbcmysql-adapter", platforms: :jruby
26
- gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
27
- gem "activerecord-jdbcmssql-adapter", platforms: :jruby
23
+ gem 'jdbc-sqlite3', platforms: :jruby
24
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
25
+ gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
26
+ gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
27
+ gem 'activerecord-jdbcmssql-adapter', platforms: :jruby
28
28
  end
29
29
 
30
- gemspec path: "../"
30
+ gemspec path: Dir.pwd
@@ -1,31 +1,32 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 5.2.0'
4
4
  gem 'arel', '~> 9'
5
5
 
6
6
  group :development, :test do
7
- gem 'bigdecimal', '1.3.5', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
7
+ gem 'bigdecimal', '1.3.5', platforms: %i[mri mingw x64_mingw mswin]
8
8
  gem 'activesupport', '~> 5.2.0'
9
9
  gem 'activemodel', '~> 5.2.0'
10
10
  gem 'activerecord', '~> 5.2.0'
11
11
 
12
- gem "sqlite3", '<= 1.3.13', platforms: [:mri]
13
- gem "mysql2", '0.4.10', platforms: [:mri]
14
- gem "pg",'< 1.0.0', platforms: [:mri]
12
+ gem 'sqlite3', '<= 1.3.13', platforms: [:mri]
13
+ gem 'mysql2', '0.4.10', platforms: [:mri]
14
+ gem 'pg', '< 1.0.0', platforms: [:mri]
15
15
 
16
- gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
17
- gem "activerecord-sqlserver-adapter", '~> 5.2', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
16
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
17
+ gem 'activerecord-sqlserver-adapter', '~> 5.2', platforms: %i[mri mingw x64_mingw mswin]
18
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
18
19
 
19
- gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
20
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
20
21
  gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0' if ENV.has_key? 'ORACLE_HOME'
21
22
 
22
23
  # for JRuby
23
24
  gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.7', platforms: :jruby
24
- gem "jdbc-sqlite3", platforms: :jruby
25
- gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
26
- gem "activerecord-jdbcmysql-adapter", platforms: :jruby
27
- gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
28
- gem "activerecord-jdbcsqlserver-adapter", '~> 52.0', platforms: :jruby
25
+ gem 'jdbc-sqlite3', platforms: :jruby
26
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
27
+ gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
28
+ gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
29
+ gem 'activerecord-jdbcsqlserver-adapter', '~> 52.0', platforms: :jruby
29
30
  end
30
31
 
31
- gemspec path: "../"
32
+ gemspec path: Dir.pwd
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 6.0.0'
4
4
 
@@ -8,22 +8,23 @@ group :development, :test do
8
8
  gem 'activemodel', '~> 6.0.0'
9
9
  gem 'activerecord', '~> 6.0.0'
10
10
 
11
- gem "sqlite3", '~> 1.4', platforms: [:mri]
12
- gem "mysql2", '0.5.2', platforms: [:mri]
13
- gem "pg",'< 1.0.0', platforms: [:mri]
11
+ gem 'sqlite3', '~> 1.4', platforms: [:mri]
12
+ gem 'mysql2', '0.5.2', platforms: [:mri]
13
+ gem 'pg', '< 1.0.0', platforms: [:mri]
14
14
 
15
- gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
16
- gem "activerecord-sqlserver-adapter", '~> 6.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
15
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
16
+ gem 'activerecord-sqlserver-adapter', '~> 6.0', platforms: %i[mri mingw x64_mingw mswin]
17
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
17
18
 
18
- gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
19
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
20
  gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
20
21
 
21
22
  # for JRuby
22
23
  gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v60.4', platforms: :jruby
23
- gem "jdbc-sqlite3", platforms: :jruby
24
- gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
25
- gem "activerecord-jdbcmysql-adapter", platforms: :jruby
26
- gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
24
+ gem 'jdbc-sqlite3', platforms: :jruby
25
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
26
+ gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
27
+ gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
27
28
  end
28
29
 
29
- gemspec path: "../"
30
+ gemspec path: Dir.pwd
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 6.1.0'
4
4
 
@@ -8,22 +8,23 @@ group :development, :test do
8
8
  gem 'activemodel', '~> 6.1.0'
9
9
  gem 'activerecord', '~> 6.1.0'
10
10
 
11
- gem "sqlite3", '~> 1.4', platforms: [:mri]
12
- gem "mysql2", '0.5.2', platforms: [:mri]
13
- gem "pg",'~> 1.1', platforms: [:mri]
11
+ gem 'sqlite3', '~> 1.4', platforms: [:mri]
12
+ gem 'mysql2', '0.5.2', platforms: [:mri]
13
+ gem 'pg', '~> 1.1', platforms: [:mri]
14
14
 
15
- gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
16
- gem "activerecord-sqlserver-adapter", '~> 6.1.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
15
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
16
+ gem 'activerecord-sqlserver-adapter', '~> 6.1.0', platforms: %i[mri mingw x64_mingw mswin]
17
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
17
18
 
18
- gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
19
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
20
  gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
20
21
 
21
22
  # for JRuby
22
23
  gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v61.1', platforms: :jruby
23
- gem "jdbc-sqlite3", platforms: :jruby
24
- gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
25
- gem "activerecord-jdbcmysql-adapter", platforms: :jruby
26
- gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
24
+ gem 'jdbc-sqlite3', platforms: :jruby
25
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
26
+ gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
27
+ gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
27
28
  end
28
29
 
29
- gemspec path: "../"
30
+ gemspec path: Dir.pwd
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 7.0.1'
4
4
 
@@ -8,15 +8,16 @@ group :development, :test do
8
8
  gem 'activemodel', '~> 7.0.1'
9
9
  gem 'activerecord', '~> 7.0.1'
10
10
 
11
- gem "sqlite3", '~> 1.4', platforms: [:mri]
12
- gem "mysql2", '0.5.2', platforms: [:mri]
13
- gem "pg",'~> 1.1', platforms: [:mri]
11
+ gem 'sqlite3', '~> 1.4', platforms: [:mri]
12
+ gem 'mysql2', '0.5.2', platforms: [:mri]
13
+ gem 'pg', '~> 1.1', platforms: [:mri]
14
14
 
15
- gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
16
- gem "activerecord-sqlserver-adapter", '~> 7.0.0.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
15
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
16
+ gem 'activerecord-sqlserver-adapter', '~> 7.0.0.0', platforms: %i[mri mingw x64_mingw mswin]
17
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
17
18
 
18
- gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
19
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
20
  gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
20
21
  end
21
22
 
22
- gemspec path: "../"
23
+ gemspec path: Dir.pwd
@@ -1,28 +1,28 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "arel_extensions/version"
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'arel_extensions/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "arel_extensions"
5
+ s.name = 'arel_extensions'
6
6
  s.version = ArelExtensions::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Yann Azoury", "Félix Bellanger", "Julien Delporte"]
9
- s.email = ["yann.azoury@faveod.com", "felix.bellanger@faveod.com", "julien.delporte@faveod.com"]
10
- s.homepage = "https://github.com/Faveod/arel-extensions"
11
- s.description = "Adds new features to Arel"
12
- s.summary = "Extending Arel"
8
+ s.authors = ['Yann Azoury', 'Félix Bellanger', 'Julien Delporte']
9
+ s.email = ['yann.azoury@faveod.com', 'felix.bellanger@faveod.com', 'julien.delporte@faveod.com']
10
+ s.homepage = 'https://github.com/Faveod/arel-extensions'
11
+ s.description = 'Adds new features to Arel'
12
+ s.summary = 'Extending Arel'
13
13
  s.license = 'MIT'
14
14
 
15
- s.rdoc_options = ["--main", "README.md"]
16
- s.extra_rdoc_files = ["MIT-LICENSE.txt", "README.md", 'functions.html']
15
+ s.rdoc_options = ['--main', 'README.md']
16
+ s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
17
17
 
18
18
  # Manifest
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.require_paths = ["lib"]
21
+ s.require_paths = ['lib']
22
22
 
23
23
  s.add_dependency('arel', '>= 6.0')
24
24
 
25
25
  s.add_development_dependency('minitest', '~> 5.9')
26
26
  s.add_development_dependency('rdoc', '>= 6.3.1')
27
27
  s.add_development_dependency('rake', '~> 12.3.3')
28
- end
28
+ end
@@ -1,24 +1,24 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "arel_extensions/version"
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'arel_extensions/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "arel_extensions"
5
+ s.name = 'arel_extensions'
6
6
  s.version = ArelExtensions::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Yann Azoury", "Félix Bellanger", "Julien Delporte"]
9
- s.email = ["yann.azoury@faveod.com", "felix.bellanger@faveod.com", "julien.delporte@faveod.com"]
10
- s.homepage = "https://github.com/Faveod/arel-extensions"
11
- s.description = "Adds new features to Arel"
12
- s.summary = "Extending Arel"
8
+ s.authors = ['Yann Azoury', 'Félix Bellanger', 'Julien Delporte']
9
+ s.email = ['yann.azoury@faveod.com', 'felix.bellanger@faveod.com', 'julien.delporte@faveod.com']
10
+ s.homepage = 'https://github.com/Faveod/arel-extensions'
11
+ s.description = 'Adds new features to Arel'
12
+ s.summary = 'Extending Arel'
13
13
  s.license = 'MIT'
14
14
 
15
- s.rdoc_options = ["--main", "README.md"]
16
- s.extra_rdoc_files = ["MIT-LICENSE.txt", "README.md", 'functions.html']
15
+ s.rdoc_options = ['--main', 'README.md']
16
+ s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
17
17
 
18
18
  # Manifest
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.require_paths = ["lib"]
21
+ s.require_paths = ['lib']
22
22
 
23
23
  s.add_dependency('activerecord', '>= 6.0')
24
24
 
data/init/mssql.sql CHANGED
File without changes
data/init/mysql.sql CHANGED
File without changes
data/init/oracle.sql CHANGED
File without changes
data/init/postgresql.sql CHANGED
File without changes
data/init/sqlite.sql CHANGED
File without changes
@@ -19,11 +19,11 @@ module ArelExtensions
19
19
  include ArelExtensions::Predications
20
20
 
21
21
  def ==(other)
22
- Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
22
+ Arel::Nodes::Equality.new self, Arel.quoted(other, self)
23
23
  end
24
24
 
25
25
  def !=(other)
26
- Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
26
+ Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require 'arel_extensions/nodes/then'
4
2
 
5
3
  module ArelExtensions
@@ -32,7 +30,7 @@ class Arel::Nodes::And
32
30
  def self.new *children
33
31
  children =
34
32
  children.flatten.map { |c|
35
- c.is_a?(self) ? c.children : c
33
+ c.is_a?(self) ? c.children : c
36
34
  }.flatten
37
35
  super(children)
38
36
  end
@@ -52,7 +50,7 @@ class Arel::Nodes::Or
52
50
  def self.new *children
53
51
  children =
54
52
  children.flatten.map { |c|
55
- c.is_a?(self) ? c.children : c
53
+ c.is_a?(self) ? c.children : c
56
54
  }.flatten
57
55
  super(*children)
58
56
  end
@@ -6,8 +6,8 @@ module ArelExtensions
6
6
  begin
7
7
  db = cnx.raw_connection
8
8
  db.enable_load_extension(1)
9
- db.load_extension("/usr/lib/sqlite3/pcre.so")
10
- db.load_extension("/usr/lib/sqlite3/extension-functions.so")
9
+ db.load_extension('/usr/lib/sqlite3/pcre.so')
10
+ db.load_extension('/usr/lib/sqlite3/extension-functions.so')
11
11
  db.enable_load_extension(0)
12
12
  rescue => e
13
13
  $load_extension_disabled = true
@@ -18,28 +18,28 @@ module ArelExtensions
18
18
 
19
19
  def add_sqlite_functions
20
20
  db = @cnx.raw_connection
21
- db.create_function("find_in_set", 1) do |func, val, list|
21
+ db.create_function('find_in_set', 1) do |func, val, list|
22
22
  case list
23
23
  when String
24
24
  i = list.split(',').index(val.to_s)
25
- func.result = i ? (i+1) : 0
25
+ func.result = i ? (i + 1) : 0
26
26
  when NilClass
27
27
  func.result = nil
28
28
  else
29
29
  i = list.to_s.split(',').index(val.to_s)
30
- func.result = i ? (i+1) : 0
30
+ func.result = i ? (i + 1) : 0
31
31
  end
32
32
  end
33
- db.create_function("instr", 1) do |func, value1, value2|
33
+ db.create_function('instr', 1) do |func, value1, value2|
34
34
  i = value1.to_s.index(value2.to_s)
35
- func.result = i ? (i+1) : 0
36
- end rescue "function instr already here (>= 3.8.5)"
35
+ func.result = i ? (i + 1) : 0
36
+ end rescue 'function instr already here (>= 3.8.5)'
37
37
  end
38
38
 
39
39
  def add_sql_functions(env_db = nil)
40
40
  env_db ||= @cnx.adapter_name
41
- env_db = 'mysql' if env_db =~ /mysql/i
42
- if env_db =~ /sqlite/i
41
+ env_db = 'mysql' if /mysql/i.match?(env_db)
42
+ if /sqlite/i.match?(env_db)
43
43
  begin
44
44
  add_sqlite_functions
45
45
  rescue => e
@@ -52,8 +52,8 @@ module ArelExtensions
52
52
  sql.split(/^GO\s*$/).each {|str|
53
53
  @cnx.execute(str.strip) unless str.blank?
54
54
  }
55
- elsif env_db =='mysql'
56
- sql.split("$$")[1..-2].each { |str|
55
+ elsif env_db == 'mysql'
56
+ sql.split('$$')[1..-2].each { |str|
57
57
  @cnx.execute(str.strip) unless str.strip.blank?
58
58
  }
59
59
  else
@@ -1,19 +1,19 @@
1
1
  module ArelExtensions
2
2
  module Comparators
3
3
  def >(other)
4
- Arel::Nodes::GreaterThan.new self, Arel::Nodes.build_quoted(other, self)
4
+ Arel::Nodes::GreaterThan.new self, Arel.quoted(other, self)
5
5
  end
6
6
 
7
7
  def >=(other)
8
- Arel::Nodes::GreaterThanOrEqual.new self, Arel::Nodes.build_quoted(other, self)
8
+ Arel::Nodes::GreaterThanOrEqual.new self, Arel.quoted(other, self)
9
9
  end
10
10
 
11
11
  def <(other)
12
- Arel::Nodes::LessThan.new self, Arel::Nodes.build_quoted(other, self)
12
+ Arel::Nodes::LessThan.new self, Arel.quoted(other, self)
13
13
  end
14
14
 
15
15
  def <=(other)
16
- Arel::Nodes::LessThanOrEqual.new self, Arel::Nodes.build_quoted(other, self)
16
+ Arel::Nodes::LessThanOrEqual.new self, Arel.quoted(other, self)
17
17
  end
18
18
 
19
19
  # REGEXP function
@@ -21,7 +21,7 @@ module ArelExtensions
21
21
  def =~(other)
22
22
  # arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
23
23
  # if arg == :string || arg == :text
24
- Arel::Nodes::Regexp.new self, convert_regexp(other)
24
+ Arel::Nodes::Regexp.new self, convert_regexp(other)
25
25
  # end
26
26
  end
27
27
 
@@ -30,7 +30,7 @@ module ArelExtensions
30
30
  def !~(other)
31
31
  # arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
32
32
  # if arg == :string || arg == :text
33
- Arel::Nodes::NotRegexp.new self, convert_regexp(other)
33
+ Arel::Nodes::NotRegexp.new self, convert_regexp(other)
34
34
  # end
35
35
  end
36
36
 
@@ -42,17 +42,17 @@ module ArelExtensions
42
42
  when String
43
43
  # Do nothing.
44
44
  when Regexp
45
- other = other.source.gsub('\A','^')
46
- other.gsub!('\z','$')
47
- other.gsub!('\Z','$')
48
- other.gsub!('\d','[0-9]')
49
- other.gsub!('\D','[^0-9]')
50
- other.gsub!('\w','[0-9A-Za-z]')
51
- other.gsub!('\W','[^A-Za-z0-9_]')
45
+ other = other.source.gsub('\A', '^')
46
+ other.gsub!('\z', '$')
47
+ other.gsub!('\Z', '$')
48
+ other.gsub!('\d', '[0-9]')
49
+ other.gsub!('\D', '[^0-9]')
50
+ other.gsub!('\w', '[0-9A-Za-z]')
51
+ other.gsub!('\W', '[^A-Za-z0-9_]')
52
52
  else
53
53
  raise(ArgumentError)
54
54
  end
55
- Arel::Nodes.build_quoted(other, self)
55
+ Arel.quoted(other, self)
56
56
  end
57
57
  end
58
58
  end
@@ -6,22 +6,22 @@ module ArelExtensions
6
6
  module DateDuration
7
7
  # function returns the year (as a number) given a date value.
8
8
  def year
9
- ArelExtensions::Nodes::Duration.new "y", self
9
+ ArelExtensions::Nodes::Duration.new 'y', self
10
10
  end
11
11
 
12
12
  # function returns the month (as a number) given a date value.
13
13
  def month
14
- ArelExtensions::Nodes::Duration.new "m", self
14
+ ArelExtensions::Nodes::Duration.new 'm', self
15
15
  end
16
16
 
17
17
  # function returns the week (as a number) given a date value.
18
18
  def week
19
- ArelExtensions::Nodes::Duration.new "w", self
19
+ ArelExtensions::Nodes::Duration.new 'w', self
20
20
  end
21
21
 
22
22
  # function returns the month (as a number) given a date value.
23
23
  def day
24
- ArelExtensions::Nodes::Duration.new "d", self
24
+ ArelExtensions::Nodes::Duration.new 'd', self
25
25
  end
26
26
 
27
27
  def wday
@@ -29,15 +29,15 @@ module ArelExtensions
29
29
  end
30
30
 
31
31
  def hour
32
- ArelExtensions::Nodes::Duration.new "h", self
32
+ ArelExtensions::Nodes::Duration.new 'h', self
33
33
  end
34
34
 
35
35
  def minute
36
- ArelExtensions::Nodes::Duration.new "mn", self
36
+ ArelExtensions::Nodes::Duration.new 'mn', self
37
37
  end
38
38
 
39
39
  def second
40
- ArelExtensions::Nodes::Duration.new "s", self
40
+ ArelExtensions::Nodes::Duration.new 's', self
41
41
  end
42
42
 
43
43
  def format(tpl, time_zone = nil)
@@ -16,33 +16,36 @@ module ArelExtensions
16
16
  # coveing all these cases.
17
17
 
18
18
  def self.column_of_via_arel_table(table_name, column_name)
19
- begin
20
- Arel::Table.engine.connection.schema_cache.columns_hash(table_name)[column_name]
21
- rescue NoMethodError
22
- nil
23
- rescue Exception => e
24
- puts "Failed to fetch column info for #{table_name}.#{column_name} ."
25
- puts "This should never be reached."
26
- puts "#{e.class}: #{e}"
27
- nil
28
- end
19
+ Arel::Table.engine.connection.schema_cache.columns_hash(table_name)[column_name]
20
+ rescue NoMethodError
21
+ nil
22
+ rescue => e
23
+ warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}: #{e}")
24
+ nil
29
25
  end
30
26
 
31
27
  def self.column_of(table_name, column_name)
28
+ pool = ActiveRecord::Base.connection.pool
32
29
  use_arel_table = !ActiveRecord::Base.connected? || \
33
- (ActiveRecord::Base.connection.pool.respond_to?(:schema_cache) && ActiveRecord::Base.connection.pool.schema_cache.nil?)
30
+ (pool.respond_to?(:schema_cache) && pool.schema_cache.nil?)
34
31
 
35
32
  if use_arel_table
36
33
  column_of_via_arel_table(table_name, column_name)
37
34
  else
38
- if ActiveRecord::Base.connection.pool.respond_to?(:pool_config)
39
- ActiveRecord::Base.connection.pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
40
- elsif ActiveRecord::Base.connection.pool.respond_to?(:schema_cache)
41
- ActiveRecord::Base.connection.pool.schema_cache.columns_hash(table_name)[column_name]
35
+ if pool.respond_to?(:pool_config)
36
+ pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
37
+ elsif pool.respond_to?(:schema_cache)
38
+ pool.schema_cache.columns_hash(table_name)[column_name]
42
39
  else
43
- puts ">>> We really shouldn't be here #{table_name}.#{column_name}"
44
40
  column_of_via_arel_table(table_name, column_name)
45
41
  end
46
42
  end
43
+ rescue ActiveRecord::ConnectionNotEstablished
44
+ column_of_via_arel_table(table_name, column_name)
45
+ rescue ActiveRecord::StatementInvalid
46
+ nil
47
+ rescue => e
48
+ warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}: #{e}")
49
+ nil
47
50
  end
48
51
  end
@@ -3,7 +3,7 @@ require 'arel'
3
3
  module ArelExtensions
4
4
  module InsertManager
5
5
  def bulk_insert(cols, data)
6
- raise ArgumentError, "cols must be present" if cols.blank?
6
+ raise ArgumentError, 'cols must be present' if cols.blank?
7
7
  columns =
8
8
  case cols.first
9
9
  when Array