as_csv 2.0.0 → 2.0.1

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: fab6c26d2cc4b35271b2e283e491551b0b543462
4
- data.tar.gz: 57575c488181311eead7ec3f0d06720d542cce3a
3
+ metadata.gz: 4d42e156f1d67a08429e702174565e9b9790dd26
4
+ data.tar.gz: 34f15ff95d6a14f7498f86af25ef0e245aa20ea2
5
5
  SHA512:
6
- metadata.gz: 1ef85d7066f7fab2bed8429e747f00a09d37bf185e27f6811dc352ee49a2b1c3f49c38661ab4cfd372eec297617e34fa39c566a6d8bc2f3c258a3a7d141c6610
7
- data.tar.gz: eb9680322c9c6aef090247f6a492b37bb94953ce177c2148df5cb018b9d7a347e2d38d998cd4f56228d4a7b95e172864e80f2cd5c25ee70e48ccb519b84fd604
6
+ metadata.gz: 370cafb8ca291e3eaae5b5e83343e388602c23d00ab1ca90e24e20026f3d4df21a604ee8e339223468b7d382c305ba2fc093ece5dd3ecb285246a021da552b2e
7
+ data.tar.gz: 06e15f34dd43979e0aa577b5de352cbe26fb7445aa28edf301fbffaa6d3e1aa88d8bf244121ef9c3751e4800f3db72415eebb56de9767b2734cd9849b8c55e09
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [Unreleased][unreleased]
7
+
8
+ - Nothing currently
9
+
10
+ ## [2.0.1] - 2015-03-21
11
+
12
+ ### Added
13
+
14
+ - Allow options to be passed-through to CSV. e.g. `puts (Foo.all + Bar.all).to_csv csv_options: {col_sep:'|'}`
15
+ - This changelog (sorry if you care about what happened before then)
16
+
17
+ ## [2.0.0] - Sometime
18
+
19
+ - Pretty sure this is actually backwards compat. Sorry.
20
+
21
+ [unreleased]: https://github.com/danielfone/as_csv/compare/v2.0.1...HEAD
22
+ [2.0.1]: https://github.com/danielfone/as_csv/compare/v2.0.0...v2.0.1
23
+ [2.0.0]: https://github.com/danielfone/as_csv/compare/v1.0.2...v2.0.0
data/README.md CHANGED
@@ -159,6 +159,20 @@ bar1,bar1-description,,acb12345
159
159
  bar2,bar2-description,,xyz98765
160
160
  ```
161
161
 
162
+ ### stdlib CSV options
163
+ If you need to pass any [options](http://docs.ruby-lang.org/en/2.0.0/CSV.html#method-c-new)
164
+ to the underlying CSV library:
165
+
166
+
167
+ ```
168
+ > puts (Foo.all + Bar.all).to_csv csv_options: {col_sep:'|'}
169
+ name|description|code|barcode
170
+ foo1|foo1-description|111|
171
+ foo2|foo2-description|222|
172
+ bar1|bar1-description||acb12345
173
+ bar2|bar2-description||xyz98765
174
+ ```
175
+
162
176
  ## Contributing
163
177
 
164
178
  1. Fork it
data/as_csv.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_runtime_dependency "activemodel", '>= 3.0'
18
18
  gem.add_runtime_dependency "actionpack", '>= 3.0'
19
+ gem.add_runtime_dependency "responders"
19
20
 
20
21
  # Tests
21
22
  gem.add_development_dependency "rails", ">= 3.0"
@@ -2,16 +2,17 @@ require 'csv'
2
2
 
3
3
  module AsCSV
4
4
  class CSVBuilder
5
- attr_reader :records, :options
5
+ attr_reader :records, :options, :csv_options
6
6
 
7
7
  def initialize(records, options={})
8
8
  @records = Array(records)
9
9
  @options = options
10
+ @csv_options = options.delete(:csv_options) || {}
10
11
  validate
11
12
  end
12
13
 
13
14
  def to_csv
14
- rows.collect { |row| CSV.generate_line row }.join
15
+ rows.collect { |row| CSV.generate_line row, csv_options }.join
15
16
  end
16
17
 
17
18
  private
@@ -1,3 +1,3 @@
1
1
  module AsCSV
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -4,6 +4,7 @@ require 'rails/all'
4
4
 
5
5
  Bundler.require
6
6
  require "as_csv"
7
+ require "responders"
7
8
 
8
9
  module Dummy
9
10
  class Application < Rails::Application
@@ -18,6 +18,20 @@ describe Widget do
18
18
  end
19
19
  end
20
20
 
21
+ describe 'dummy with csv options' do
22
+ subject(:dummy_widget) { Widget.new :name => "widget-name", :description => 'widget-description', :code => 1234 }
23
+
24
+ describe :to_csv do
25
+ subject { dummy_widget.to_csv(csv_options: {col_sep:'|'})}
26
+ it do
27
+ should == <<-CSV.strip_heredoc
28
+ id|name|description|code
29
+ |widget-name|widget-description|1234
30
+ CSV
31
+ end
32
+ end
33
+ end
34
+
21
35
  describe 'collection' do
22
36
  before do
23
37
  Widget.create! [
@@ -44,4 +58,4 @@ describe Widget do
44
58
  end
45
59
  end
46
60
 
47
- end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Fone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: responders
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rails
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +118,7 @@ files:
104
118
  - ".gitignore"
105
119
  - ".rspec"
106
120
  - ".travis.yml"
121
+ - CHANGELOG.md
107
122
  - Gemfile
108
123
  - LICENSE.txt
109
124
  - README.md
@@ -179,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
194
  version: '0'
180
195
  requirements: []
181
196
  rubyforge_project:
182
- rubygems_version: 2.4.1
197
+ rubygems_version: 2.4.6
183
198
  signing_key:
184
199
  specification_version: 4
185
200
  summary: Instant CSV support for Rails