activerecord-postgres-array 0.0.6 → 0.0.7
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.
data/README.textile
CHANGED
@@ -30,7 +30,7 @@ activerecord-postgres-hstore and activerecord-postgres-array both monkeypatch @A
|
|
30
30
|
h2. Current limitations
|
31
31
|
|
32
32
|
* Parsing of multi-dimensional postgres array strings is currently not implemented.
|
33
|
-
* String and
|
33
|
+
* String, Decimal and Integer arrays have been tested, but other array types have not been. Type casting will need to be implemented for booleans, dates, etc
|
34
34
|
|
35
35
|
h3. Future enhancements
|
36
36
|
|
@@ -20,7 +20,7 @@ class String
|
|
20
20
|
if empty?
|
21
21
|
[]
|
22
22
|
else
|
23
|
-
elements = match(/\{(.*)\}/).captures.first.gsub(/\\"/, '$ESCAPED_DOUBLE_QUOTE$').split(/(
|
23
|
+
elements = match(/\{(.*)\}/).captures.first.gsub(/\\"/, '$ESCAPED_DOUBLE_QUOTE$').split(/(?:,)(?=(?:[^"]|"[^"]*")*$)/)
|
24
24
|
elements = elements.map do |e|
|
25
25
|
res = e.gsub('$ESCAPED_DOUBLE_QUOTE$', '"').gsub("\\\\", "\\").gsub(/^"/, '').gsub(/"$/, '').gsub("''", "'").strip
|
26
26
|
res == 'NULL' ? nil : res
|
@@ -28,9 +28,11 @@ class String
|
|
28
28
|
|
29
29
|
if base_type == :decimal
|
30
30
|
elements.collect(&:to_d)
|
31
|
+
elsif base_type == :integer
|
32
|
+
elements.collect(&:to_i)
|
31
33
|
else
|
32
34
|
elements
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
|
-
end
|
38
|
+
end
|
data/spec/integration_spec.rb
CHANGED
@@ -3,10 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe Article do
|
4
4
|
describe ".create" do
|
5
5
|
it "builds valid arrays" do
|
6
|
-
article = Article.create(:languages => ["English", "German"])
|
6
|
+
article = Article.create(:languages => ["English", "German"], :author_ids => [1,2,3])
|
7
7
|
article.reload
|
8
8
|
article.languages_before_type_cast.should == "{English,German}"
|
9
9
|
article.languages.should == ["English", "German"]
|
10
|
+
article.author_ids_before_type_cast.should == "{1,2,3}"
|
11
|
+
article.author_ids.should == [1,2,3]
|
10
12
|
end
|
11
13
|
|
12
14
|
it "escapes single quotes correctly" do
|
data/spec/internal/db/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres-array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Connor
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-08 00:00:00
|
18
|
+
date: 2012-02-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|