as_csv 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +14 -0
- data/as_csv.gemspec +1 -0
- data/lib/as_csv/csv_builder.rb +3 -2
- data/lib/as_csv/version.rb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/models/widget_spec.rb +15 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d42e156f1d67a08429e702174565e9b9790dd26
|
4
|
+
data.tar.gz: 34f15ff95d6a14f7498f86af25ef0e245aa20ea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/as_csv/csv_builder.rb
CHANGED
@@ -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
|
data/lib/as_csv/version.rb
CHANGED
data/spec/models/widget_spec.rb
CHANGED
@@ -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.
|
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:
|
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.
|
197
|
+
rubygems_version: 2.4.6
|
183
198
|
signing_key:
|
184
199
|
specification_version: 4
|
185
200
|
summary: Instant CSV support for Rails
|