activerecord-postgres-array 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 Decimal arrays have been tested, but other array types have not been. Type casting will need to be implemented for booleans, dates, etc
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "activerecord-postgres-array"
3
- s.version = "0.0.6"
3
+ s.version = "0.0.7"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Tim Connor"]
@@ -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(/(,)(?=(?:[^"]|"[^"]*")*$)/).reject {|e| e == ',' }
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
@@ -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
@@ -1,6 +1,7 @@
1
1
  ActiveRecord::Schema.define do
2
2
  create_table(:articles, :force => true) do |t|
3
- t.string :name
4
- t.string_array :languages
3
+ t.string :name
4
+ t.string_array :languages
5
+ t.integer_array :author_ids
5
6
  end
6
7
  end
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'active_support/dependencies'
3
4
 
4
5
  Bundler.require :default, :development
5
6
 
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
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 +13:00
18
+ date: 2012-02-08 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency