postgres-copy 1.1.1 → 1.1.2

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: 3a328003e2235ee8109a4bf5dae548d65d5d8b5e
4
- data.tar.gz: 0169341e9fe16a65cf44338a5e8bed35f216f311
3
+ metadata.gz: 3cc595142d45d6053c54bac79e0855c4d8136856
4
+ data.tar.gz: 548bbff5d3505a7c9721d0d69f20313072770dd3
5
5
  SHA512:
6
- metadata.gz: debece2dead55d3891b5b671319bdc2bcd394bbc6868a9b6df6a33eda1dbe4b2bf9b04d4a038ff27a010a8a6fd886e766e5e58fa456329d9c08010174627d114
7
- data.tar.gz: ca15b8aa0d82b5a38b0320bb04264bb7f3f6bdd6667c2106bac681be7849b0deee63e57527b3c7785267bf059c79e5964a5a5f899a227b052a4617fb575fffe4
6
+ metadata.gz: e15905d7bcd481f38153decfc9350d0220642c62b35ea7d285293b3ccf2f50fd8cf4e87d1e4bc8c49bcb120e15b6a422b78f05313e3587ca94e0b578561fd28a
7
+ data.tar.gz: 1da873e2f16c582afb38eef9d4dba009067446df3c6835228ec31c1cf2253a8690dd3e716f162a05032b6f0d0becf0d8defcca575cf29c101755c9f651c88935
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgres-copy (1.1.1)
4
+ postgres-copy (1.1.2)
5
5
  activerecord (>= 4.0)
6
6
  pg (>= 0.17)
7
7
  responders
@@ -1,3 +1,5 @@
1
+ require 'csv'
2
+
1
3
  module PostgresCopy
2
4
  module ActsAsCopyTarget
3
5
  extend ActiveSupport::Concern
@@ -84,10 +86,10 @@ module PostgresCopy
84
86
  while line = io.gets do
85
87
  next if line.strip.size == 0
86
88
  if block_given?
87
- row = line.strip.split(options[:delimiter],-1)
89
+ row = CSV.parse_line(line.strip, {:col_sep => options[:delimiter]})
88
90
  yield(row)
89
91
  next if row.all?{|f| f.nil? }
90
- line = row.join(options[:delimiter]) + "\n"
92
+ line = CSV.generate_line(row, {:col_sep => options[:delimiter]})
91
93
  end
92
94
  connection.raw_connection.put_copy_data line
93
95
  end
@@ -5,7 +5,7 @@ $:.unshift lib unless $:.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "postgres-copy"
8
- s.version = "1.1.1"
8
+ s.version = "1.1.2"
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = ">= 1.9.3"
11
11
  s.authors = ["Diogo Biazus"]
@@ -129,6 +129,18 @@ describe "COPY FROM" do
129
129
  TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test, again'}]
130
130
  end
131
131
 
132
+ it "should import lines with commas inside fields with block given" do
133
+ File.open(File.expand_path('spec/fixtures/comma_inside_field.csv'), 'r') do |file|
134
+ TestModel.copy_from(file) do |row|
135
+ # since our CSV line look like this: {1,"test, again"} we expect only two elements withing row
136
+ row.size.should == 2
137
+ row[0].should == '1'
138
+ row[1].should == 'test, again'
139
+ end
140
+ end
141
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test, again'}]
142
+ end
143
+
132
144
  it "should import with custom null expression from path" do
133
145
  TestModel.copy_from File.expand_path('spec/fixtures/special_null_with_header.csv'), :null => 'NULL'
134
146
  TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => nil}]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres-copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diogo Biazus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg