arel_extensions 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/init/mssql.sql +18 -2
- data/lib/arel_extensions/math.rb +1 -0
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +1 -0
- data/test/with_ar/all_agnostic_test.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81a5a19e45f8b5b0a625cc277f2a99cbd5b4824d
|
4
|
+
data.tar.gz: 91a0b61f9d7804eb5c8f54a679f90fb25d1c8aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/arel_extensions/math.rb
CHANGED
@@ -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)
|
@@ -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.
|
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-
|
13
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: arel
|