copy_csv 0.1.0 → 1.0.0
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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +12 -1
- data/lib/copy_csv.rb +15 -2
- data/lib/copy_csv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c8fd7fec59eb36302453b825ded8c7f2d386e5
|
4
|
+
data.tar.gz: b1941e33bb62c4644cc3503a44fa0dfb266d119e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8902421ed37191cd383bc24f2bfe7fdb732dcc2790ff726b566b9b6009e387122c722fd0c863649fd6ddc75c87429f31bf6139ab512c0deb59b38bdf3367ce0a
|
7
|
+
data.tar.gz: f8010477bdefc5d105f9f842e90cd964a04794c05cd1c292b8b2dfa084d3b8bbe18aea36c3ba30e31b0875a427bf415d3152a138175b6cb79ab894c35f7b347d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# copy_csv
|
2
2
|
|
3
3
|
A useful gem for converting an `ActiveRecord` Relation into a CSV formatted
|
4
4
|
string.
|
5
5
|
|
6
|
+
[](https://badge.fury.io/rb/copy_csv)
|
7
|
+
|
8
|
+
View it on [RubyGems](https://rubygems.org/gems/copy_csv)
|
9
|
+
|
6
10
|
## Basic Example
|
7
11
|
|
8
12
|
There are a few users that have unsubscribed from your mailing list. You want
|
@@ -20,6 +24,9 @@ But someone else also wants to see the list, but in Excel. This is where
|
|
20
24
|
File.open("unsubscribed_users.csv", "w") do |file|
|
21
25
|
User.where(unsubscribed: true).copy_csv(file)
|
22
26
|
end
|
27
|
+
|
28
|
+
# Alternatively, you can use `write_to_csv` to not have to deal with opening a file
|
29
|
+
User.where(unsubscribed: true).write_to_csv("unsubscribed_users.csv")
|
23
30
|
```
|
24
31
|
|
25
32
|
`unsubscribed_users.csv` will now contain all of the Users that have
|
@@ -81,6 +88,10 @@ to use it in the rails console, your can just include it at will:
|
|
81
88
|
|
82
89
|
And it can be used in that console session.
|
83
90
|
|
91
|
+
## Documentation
|
92
|
+
|
93
|
+
View the [docs](https://www.rubydoc.info/gems/copy_csv/0.1.0).
|
94
|
+
|
84
95
|
## Development
|
85
96
|
|
86
97
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/copy_csv.rb
CHANGED
@@ -11,8 +11,8 @@ module CopyCsv
|
|
11
11
|
#
|
12
12
|
# Example
|
13
13
|
#
|
14
|
-
# File.open("
|
15
|
-
# User.where(unsubscribed: false).copy_csv(
|
14
|
+
# File.open("unsubscribed_users.csv", "w") do |file|
|
15
|
+
# User.where(unsubscribed: false).copy_csv(file)
|
16
16
|
# end
|
17
17
|
#
|
18
18
|
# Returns nil
|
@@ -30,5 +30,18 @@ module CopyCsv
|
|
30
30
|
|
31
31
|
nil
|
32
32
|
end
|
33
|
+
|
34
|
+
# Opens the file provided and writes the relation to it as a CSV.
|
35
|
+
#
|
36
|
+
# Example
|
37
|
+
#
|
38
|
+
# User.where(unsubscribed: false).write_to_csv("unsubscribed_users.csv")
|
39
|
+
#
|
40
|
+
# Returns nil
|
41
|
+
def write_to_csv(file_name, mode = "w")
|
42
|
+
File.open(file_name, mode) do |file|
|
43
|
+
all.copy_csv(file)
|
44
|
+
end
|
45
|
+
end
|
33
46
|
end
|
34
47
|
end
|
data/lib/copy_csv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Stumbaugh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|