magic-report 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b11733b1128011acfba29bf24cbf2846ce42e226aeccadfcdfc6ce713c2b1b3e
4
- data.tar.gz: 0dbec29ea7c05acf3744fc1a62d4b200455a88926d1e938826243df683d9ce93
3
+ metadata.gz: 44873b50d04637fb2399066a73450da8572fcbdece144c679d024692e436d155
4
+ data.tar.gz: cc0e332d579ed96f7aa2fa511039c55b727887729e2c49481b6bb1dd00ce6ad0
5
5
  SHA512:
6
- metadata.gz: ad63138a1fe01308e5ddfef0f50d3feb04ae5dd49e9fe8c2e81dcac6ed5f376daf32de12baf1912695c798ade584d96652d7c1c0a0fc6f801992fd41c0a09bce
7
- data.tar.gz: 2fff4d4f90864fded9a18846e718fbc82671907f106ce16c5240df94d57d2e92c27c2f7e423d02da1ee88a93b4f49a21db201636ffc04bb1b9c020c04a74d562
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-operation"
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
- headings:
43
- user:
44
- id: ID
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
- headings:
84
- user:
85
- id: ID
86
- is_admin: Admin?
87
- address: User address
88
- cars: Car
89
- shipping_address: Shipping address
90
- billing_address: Billing address
91
- car:
92
- name: Name
93
- address:
94
- address_line_1: Line 1
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
@@ -4,7 +4,7 @@ module MagicReport
4
4
  class Report
5
5
  module ClassHelpers
6
6
  def name_from_class
7
- ::MagicReport::Utils.underscore(self.class.name)
7
+ ::MagicReport::Utils.underscore(self.class.name).tr("/", ".")
8
8
  end
9
9
 
10
10
  def fields_from_class
@@ -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
@@ -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
@@ -25,7 +25,7 @@ module MagicReport
25
25
  # @param name is the report name
26
26
  # @key is a field
27
27
  def t(name:, key:)
28
- I18n.translate!("magic_report.headings.#{name}.#{key}")
28
+ I18n.translate!("magic_report.#{name}.#{key}")
29
29
  end
30
30
 
31
31
  module_function :underscore
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MagicReport
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pankratev