arel_extensions 0.9.0 → 0.9.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
  SHA1:
3
- metadata.gz: d3be3f3b4a82f0721265a42e8ae75fe66da12ba3
4
- data.tar.gz: a1660c2b64388e6e56bf442de63504da32c2c5ca
3
+ metadata.gz: 81a5a19e45f8b5b0a625cc277f2a99cbd5b4824d
4
+ data.tar.gz: 91a0b61f9d7804eb5c8f54a679f90fb25d1c8aaf
5
5
  SHA512:
6
- metadata.gz: 4465b08c98214889ca8be08d437a49deeb59df7de899095bcb4c4a7e7ff5d11c8c1cf50a7f8961d0f73b39b5ba0da2db36cfadd3fda4a4e8ee2eaacdc5251978
7
- data.tar.gz: 5781edd20996ca251937563e1fa15a6fa453a250654aa8191fade92b56970edcb205fe1f5cb37659cbd80460451d0cac858a32f8733919aa6b29bf26640eb519
6
+ metadata.gz: 68e49c3d6bf45935f491389bc15e9338b3ba981b42fac1db5619ef4b0a76cb74c239099207396814f2ffdf3c9af6cc0fb932779d163297ea2e099d5650912f68
7
+ data.tar.gz: da9a008e7e3d3b9c55e3db8eec18444a20608a93c9cadfeb84166c86adeea1a5a7285b80d02bffea407b2301c497c5b3efe7664a3e7aa156cbc8096381222c75
data/init/mssql.sql CHANGED
@@ -2,13 +2,29 @@ IF OBJECT_ID (N'dbo.TRIM', N'FN') IS NOT NULL
2
2
  DROP FUNCTION dbo.TRIM;
3
3
  GO
4
4
  CREATE FUNCTION dbo.TRIM (@string VARCHAR(MAX))
5
- RETURNS VARCHAR(MAX)
6
- AS
5
+ RETURNS VARCHAR(MAX) AS
7
6
  BEGIN
8
7
  RETURN LTRIM(RTRIM(@string));
9
8
  END;
10
9
  GO
11
10
 
11
+ IF OBJECT_ID (N'dbo.TrimChar', N'FN') IS NOT NULL
12
+ DROP FUNCTION dbo.TrimChar;
13
+ GO
14
+ CREATE FUNCTION dbo.TrimChar(@value nvarchar(4000), @c nchar(1))
15
+ RETURNS nvarchar(4000) AS
16
+ BEGIN
17
+ set @value = REPLACE(@value, ' ', '~') -- replace all spaces with an unused character
18
+ set @value = REPLACE(@value, @c, ' ') -- replace the character to trim with a space
19
+ set @value = LTRIM(RTRIM(@value)) -- trim
20
+ set @value = REPLACE(@value, ' ', @c) -- replace back all spaces with the trimmed character
21
+ set @value = REPLACE(@value, '~', ' ') -- replace back all never-used characters with a space
22
+
23
+ RETURN @value
24
+ END;
25
+
26
+ GO
27
+
12
28
  -----------------------------
13
29
  -- GO
14
30
 
@@ -11,6 +11,7 @@ module ArelExtensions
11
11
  #String and others (convert in string) allows you to concatenate 2 or more strings together.
12
12
  #Date and integer adds or subtracts a specified time interval from a date.
13
13
  def +(other)
14
+ return ArelExtensions::Nodes::Concat.new [self, other] if self.is_a?(Arel::Nodes::Quoted)
14
15
  arg = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
15
16
  if arg == :integer
16
17
  other = other.to_i if other.is_a?(String)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ArelExtensions
3
- VERSION = "0.9.0".freeze
3
+ VERSION = "0.9.1".freeze
4
4
  end
@@ -20,4 +20,5 @@ begin
20
20
  end
21
21
  rescue LoadError
22
22
  rescue => e
23
+ e
23
24
  end
@@ -163,6 +163,7 @@ module ArelExtensions
163
163
  def test_concat
164
164
  assert_equal 'Camille Camille', t(@camille, @name + ' ' + @name)
165
165
  assert_equal 'Laure 2', t(@laure, @name + ' ' + 2)
166
+ assert_equal 'Test Laure', t(@laure, Arel::Nodes.build_quoted('Test ') + @name)
166
167
  skip "TODO: find a way... to do group_concat/listagg in SQL Server" if @env_db == 'mssql'
167
168
  if @env_db == 'postgresql'
168
169
  assert_equal "Lucas Sophie", t(User.reorder(nil).from(User.select(:name).where(:name => ['Lucas', 'Sophie']).reorder(:name).as('user_tests')), @name.group_concat(' '))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-06 00:00:00.000000000 Z
13
+ date: 2016-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel