streamy_csv 0.1.0 → 0.2.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.
- data/README.md +29 -2
- data/lib/streamy_csv/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# StreamyCsv
|
2
2
|
|
3
|
-
|
3
|
+
Streams CSV files one row at a time as live data is generated instead of waiting for the whole file to be created and then sent to the client. Works on most standard web servers including Nginx, Passenger, Unicorn, Thin etc., but does NOT work on Webrick.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -17,8 +17,35 @@ Or install it yourself as:
|
|
17
17
|
$ gem install streamy_csv
|
18
18
|
|
19
19
|
## Usage
|
20
|
+
In your model:
|
20
21
|
|
21
|
-
|
22
|
+
class MyModel
|
23
|
+
|
24
|
+
def self.header_row
|
25
|
+
CSV::Row([:name, :title], ['Name', 'Title'], true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_csv_row
|
29
|
+
CSV::Row(name: name, title: title)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
In your controller:
|
36
|
+
|
37
|
+
Class ExportsController
|
38
|
+
|
39
|
+
def index
|
40
|
+
|
41
|
+
stream_csv('data.csv', MyModel.header_row) do |rows|
|
42
|
+
MyModel.find_each do |my_model|
|
43
|
+
rows << my_model.to_csv_row
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
22
49
|
|
23
50
|
## Contributing
|
24
51
|
|
data/lib/streamy_csv/version.rb
CHANGED