pg_csv 0.1.5 → 0.1.6
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/lib/pg_csv.rb +7 -8
 - data/lib/pg_csv_version.rb +2 -2
 - data/spec/pg_csv_spec.rb +18 -2
 - metadata +5 -5
 
    
        data/lib/pg_csv.rb
    CHANGED
    
    | 
         @@ -85,7 +85,7 @@ class PgCsv 
     | 
|
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                def export_to_stream(stream)
         
     | 
| 
       87 
87 
     | 
    
         
             
                  count = write_csv(stream)
         
     | 
| 
       88 
     | 
    
         
            -
                  stream.flush if stream.respond_to?(:flush)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  stream.flush if stream.respond_to?(:flush) && count > 0
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
90 
     | 
    
         
             
                  info "<= done exporting (#{count}) records."
         
     | 
| 
       91 
91 
     | 
    
         
             
                end
         
     | 
| 
         @@ -196,12 +196,11 @@ class PgCsv 
     | 
|
| 
       196 
196 
     | 
    
         | 
| 
       197 
197 
     | 
    
         
             
              def self.with_temp_file(dest, tmp_dir = '/tmp', &block)
         
     | 
| 
       198 
198 
     | 
    
         
             
                require 'fileutils'
         
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
                 
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
                FileUtils.mv(tempfile.path, dest)
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                filename = File.join(tmp_dir, "pg_csv_#{Time.now.to_f}_#{rand(1000000)}")
         
     | 
| 
      
 201 
     | 
    
         
            +
                block[filename]
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
                FileUtils.mv(filename, dest)
         
     | 
| 
       205 
204 
     | 
    
         
             
              end
         
     | 
| 
       206 
205 
     | 
    
         | 
| 
       207 
     | 
    
         
            -
            end
         
     | 
| 
      
 206 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/pg_csv_version.rb
    CHANGED
    
    | 
         @@ -1,3 +1,3 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class PgCsv
         
     | 
| 
       2 
     | 
    
         
            -
              VERSION = "0.1. 
     | 
| 
       3 
     | 
    
         
            -
            end
         
     | 
| 
      
 2 
     | 
    
         
            +
              VERSION = "0.1.6"
         
     | 
| 
      
 3 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/pg_csv_spec.rb
    CHANGED
    
    | 
         @@ -82,10 +82,18 @@ describe PgCsv do 
     | 
|
| 
       82 
82 
     | 
    
         
             
              end
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
              describe "using temp file" do
         
     | 
| 
       85 
     | 
    
         
            -
                it "at least file should return to target" do
         
     | 
| 
      
 85 
     | 
    
         
            +
                it "at least file should return to target and set correct chmod" do
         
     | 
| 
       86 
86 
     | 
    
         
             
                  File.exists?(@name).should be_false
         
     | 
| 
       87 
87 
     | 
    
         
             
                  PgCsv.new(:sql => @sql, :temp_file => true, :temp_dir => tmp_dir).export(@name)
         
     | 
| 
       88 
88 
     | 
    
         
             
                  with_file(@name){|d| d.should == "4,5,6\n1,2,3\n" }
         
     | 
| 
      
 89 
     | 
    
         
            +
                  sprintf("%o", File.stat(@name).mode).to_i.should >= 100660
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                it "same with gzip" do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  File.exists?(@name).should be_false
         
     | 
| 
      
 94 
     | 
    
         
            +
                  PgCsv.new(:sql => @sql, :temp_file => true, :temp_dir => tmp_dir, :type => :gzip).export(@name)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  with_gzfile(@name){|d| d.should == "4,5,6\n1,2,3\n" }
         
     | 
| 
      
 96 
     | 
    
         
            +
                  sprintf("%o", File.stat(@name).mode).to_i.should >= 100660
         
     | 
| 
       89 
97 
     | 
    
         
             
                end
         
     | 
| 
       90 
98 
     | 
    
         
             
              end
         
     | 
| 
       91 
99 
     | 
    
         | 
| 
         @@ -94,6 +102,7 @@ describe PgCsv do 
     | 
|
| 
       94 
102 
     | 
    
         
             
                  File.exists?(@name).should be_false
         
     | 
| 
       95 
103 
     | 
    
         
             
                  PgCsv.new(:sql => @sql, :type => :gzip).export(@name)
         
     | 
| 
       96 
104 
     | 
    
         
             
                  with_gzfile(@name){|d| d.should == "4,5,6\n1,2,3\n" }
         
     | 
| 
      
 105 
     | 
    
         
            +
                  sprintf("%o", File.stat(@name).mode).to_i.should >= 100660
         
     | 
| 
       97 
106 
     | 
    
         
             
                end
         
     | 
| 
       98 
107 
     | 
    
         | 
| 
       99 
108 
     | 
    
         
             
                it "plain export" do
         
     | 
| 
         @@ -113,6 +122,7 @@ describe PgCsv do 
     | 
|
| 
       113 
122 
     | 
    
         
             
                it "file as default" do
         
     | 
| 
       114 
123 
     | 
    
         
             
                  PgCsv.new(:sql => @sql, :type => :file).export(@name)
         
     | 
| 
       115 
124 
     | 
    
         
             
                  with_file(@name){|d| d.should == "4,5,6\n1,2,3\n" }            
         
     | 
| 
      
 125 
     | 
    
         
            +
                  sprintf("%o", File.stat(@name).mode).to_i.should >= 100660
         
     | 
| 
       116 
126 
     | 
    
         
             
                end
         
     | 
| 
       117 
127 
     | 
    
         | 
| 
       118 
128 
     | 
    
         
             
                it "yield export" do
         
     | 
| 
         @@ -142,6 +152,12 @@ describe PgCsv do 
     | 
|
| 
       142 
152 
     | 
    
         | 
| 
       143 
153 
     | 
    
         
             
                  with_gzfile(@name){|d| d.should == "q|w|e\n4|5|6\n1|2|3\n1*2*3\n4*5*6\n" }
         
     | 
| 
       144 
154 
     | 
    
         
             
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                it "gzip with empty content" do
         
     | 
| 
      
 157 
     | 
    
         
            +
                  File.exists?(@name).should be_false
         
     | 
| 
      
 158 
     | 
    
         
            +
                  PgCsv.new(:sql => "select a,b,c from tests where a = -1", :type => :gzip).export(@name, :temp_file => true, :temp_dir => tmp_dir)
         
     | 
| 
      
 159 
     | 
    
         
            +
                  with_gzfile(@name){|d| d.should == "" }
         
     | 
| 
      
 160 
     | 
    
         
            +
                end
         
     | 
| 
       145 
161 
     | 
    
         
             
              end
         
     | 
| 
       146 
162 
     | 
    
         | 
| 
       147 
163 
     | 
    
         
             
              it "custom row proc" do
         
     | 
| 
         @@ -154,4 +170,4 @@ describe PgCsv do 
     | 
|
| 
       154 
170 
     | 
    
         
             
                with_file(@name){|d| d.should == "4-|-5-|-6\n1-|-2-|-3\n" }
         
     | 
| 
       155 
171 
     | 
    
         
             
              end
         
     | 
| 
       156 
172 
     | 
    
         | 
| 
       157 
     | 
    
         
            -
            end
         
     | 
| 
      
 173 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: pg_csv
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.6
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012-08- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-08-29 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: pg
         
     | 
| 
         @@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       110 
110 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       111 
111 
     | 
    
         
             
                  segments:
         
     | 
| 
       112 
112 
     | 
    
         
             
                  - 0
         
     | 
| 
       113 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 113 
     | 
    
         
            +
                  hash: -2157019647217736024
         
     | 
| 
       114 
114 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       115 
115 
     | 
    
         
             
              none: false
         
     | 
| 
       116 
116 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -119,10 +119,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       119 
119 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       120 
120 
     | 
    
         
             
                  segments:
         
     | 
| 
       121 
121 
     | 
    
         
             
                  - 0
         
     | 
| 
       122 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 122 
     | 
    
         
            +
                  hash: -2157019647217736024
         
     | 
| 
       123 
123 
     | 
    
         
             
            requirements: []
         
     | 
| 
       124 
124 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       125 
     | 
    
         
            -
            rubygems_version: 1.8. 
     | 
| 
      
 125 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
       126 
126 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       127 
127 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       128 
128 
     | 
    
         
             
            summary: Fast AR/PostgreSQL csv export. Used pg function 'copy to csv'. Effective
         
     |