magic-report 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -18
- data/lib/magic_report/report/class_helpers.rb +1 -1
- data/lib/magic_report/report/csv.rb +8 -2
- data/lib/magic_report/report.rb +7 -0
- data/lib/magic_report/utils.rb +1 -1
- data/lib/magic_report/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44873b50d04637fb2399066a73450da8572fcbdece144c679d024692e436d155
|
4
|
+
data.tar.gz: cc0e332d579ed96f7aa2fa511039c55b727887729e2c49481b6bb1dd00ce6ad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65166e27d443bef84cd1fa581cf6da78fbc2359668190cc5c9cfc877fa1caf81274981c92f2f20da4ccdc3c1d5990ec463c08c6fd761ee912dd2f4716b90faa5
|
7
|
+
data.tar.gz: 37fb6590fa41adb3d48396ecaad42a9ae57893c64a109cf93281a7e64cbed5ea87d17b1494d28670a59dad2252afdf64bbf2d7ba444c3d3e3bc7c0f867b9e5a9
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ An easy way to export data to CSV
|
|
9
9
|
Add this line to your application’s Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem "magic-
|
12
|
+
gem "magic-report", require: "magic_report"
|
13
13
|
```
|
14
14
|
|
15
15
|
## Getting Started
|
@@ -39,10 +39,9 @@ Also, for each report you must provide locales file:
|
|
39
39
|
```yaml
|
40
40
|
en:
|
41
41
|
magic_report:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
is_admin: Admin?
|
42
|
+
user:
|
43
|
+
id: ID
|
44
|
+
is_admin: Admin?
|
46
45
|
```
|
47
46
|
|
48
47
|
CSV will be
|
@@ -80,19 +79,18 @@ Because we have explicitly said that the user `has_many :cars`, the number of li
|
|
80
79
|
```yaml
|
81
80
|
en:
|
82
81
|
magic_report:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
city: City
|
82
|
+
user:
|
83
|
+
id: ID
|
84
|
+
is_admin: Admin?
|
85
|
+
address: User address
|
86
|
+
cars: Car
|
87
|
+
shipping_address: Shipping address
|
88
|
+
billing_address: Billing address
|
89
|
+
car:
|
90
|
+
name: Name
|
91
|
+
address:
|
92
|
+
address_line_1: Line 1
|
93
|
+
city: City
|
96
94
|
```
|
97
95
|
|
98
96
|
CSV will be
|
@@ -19,14 +19,20 @@ module MagicReport
|
|
19
19
|
report.result.each do |row|
|
20
20
|
row.to_h.each { |nested_row| csv << nested_row.values }
|
21
21
|
end
|
22
|
-
# ensure
|
23
|
-
# file.close
|
24
22
|
end
|
25
23
|
|
24
|
+
# Don't forget to unlink in production code
|
26
25
|
def unlink
|
26
|
+
file.close
|
27
27
|
file.unlink
|
28
28
|
end
|
29
29
|
|
30
|
+
def io
|
31
|
+
io = csv.to_io
|
32
|
+
io.rewind
|
33
|
+
io
|
34
|
+
end
|
35
|
+
|
30
36
|
private
|
31
37
|
|
32
38
|
def write_headers
|
data/lib/magic_report/report.rb
CHANGED
@@ -29,6 +29,13 @@ module MagicReport
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def as_attachment
|
33
|
+
{
|
34
|
+
mime_type: "text/csv",
|
35
|
+
content: as_csv.io
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
32
39
|
def headings
|
33
40
|
@headings ||= (fields.map { |field| t(field.key) } + has_one.map { |association| association.report.headings } + has_many.map { |association| association.report.headings }).flatten
|
34
41
|
end
|
data/lib/magic_report/utils.rb
CHANGED
data/lib/magic_report/version.rb
CHANGED