lp_csv_exportable 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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/lp_csv_exportable/can_export_as_csv.rb +7 -10
- data/lib/lp_csv_exportable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27cb7b83786f789431b64a9bbf8873e3123bedcf
|
4
|
+
data.tar.gz: 13706fb398738f69d914c5161a526c9973feb1d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9d48093288b6d91c293bce15cfc4aad9dc13085be75e2acdb4e6d86fa1ea607a7671bdd7007462fc9bcacdc73421dace781813edbdd6d63f9af031f2df3739
|
7
|
+
data.tar.gz: fc3919e22f6ef0d83a7b57f339880e544f0a6ab0e59d5be21b17868f1f6c9445fd08d8394d46f2605181dd2700e4d6ad25cfac698c34e8181d0fae8248e2a594
|
data/README.md
CHANGED
@@ -41,7 +41,8 @@ And then to export, simply instantiate your class and pass in your `collection`,
|
|
41
41
|
|
42
42
|
respond_to do |format|
|
43
43
|
format.csv do
|
44
|
-
export = ExportUsers.new
|
44
|
+
export = ExportUsers.new
|
45
|
+
export.collection = users
|
45
46
|
send_data export.to_csv
|
46
47
|
end
|
47
48
|
end
|
@@ -1,16 +1,11 @@
|
|
1
1
|
module LpCSVExportable
|
2
2
|
module CanExportAsCSV
|
3
|
-
|
3
|
+
attr_accessor :collection
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.extend ClassMethods
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize(args = {})
|
10
|
-
@collection = args[:collection]
|
11
|
-
after_init(args)
|
12
|
-
end
|
13
|
-
|
14
9
|
def to_csv
|
15
10
|
CSV.generate do |csv|
|
16
11
|
csv << headers
|
@@ -22,10 +17,6 @@ module LpCSVExportable
|
|
22
17
|
|
23
18
|
private
|
24
19
|
|
25
|
-
def after_init(args = {})
|
26
|
-
# hook
|
27
|
-
end
|
28
|
-
|
29
20
|
def columns
|
30
21
|
self.class.columns_hashes.map do |hash|
|
31
22
|
CSVColumn.new(hash)
|
@@ -64,6 +55,12 @@ module LpCSVExportable
|
|
64
55
|
end
|
65
56
|
end
|
66
57
|
|
58
|
+
def collection
|
59
|
+
raise 'collection has not been set on the class' unless @collection
|
60
|
+
raise 'collection must respond to map method' unless @collection.respond_to?(:map)
|
61
|
+
@collection
|
62
|
+
end
|
63
|
+
|
67
64
|
# Configuration...
|
68
65
|
module ClassMethods
|
69
66
|
def column(header, options = {})
|