relational_exporter 0.0.1 → 0.0.2
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/lib/relational_exporter/version.rb +1 -1
- data/lib/relational_exporter.rb +12 -3
- 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: 93369bce5ffa225e191684a1b1655bede21b40ce
|
|
4
|
+
data.tar.gz: 4b811e535dedd706361921e85d204938436c8912
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9eae62da777df4f3991a206323d80351cced31ff9d86a2547d884ea1c92058c16198ded18819f877769fdd9983145b960ea0a9dd063001e2831e310c3506e83e
|
|
7
|
+
data.tar.gz: 5c2d7546a87f69f34a481873769b619bab48cf6cbc751f5b75162f703ff88e1a9eb28928a8428832e5efa8af62a2e97b6bdf6ae185df4e9c97617ffc10ce625e
|
data/lib/relational_exporter.rb
CHANGED
|
@@ -36,16 +36,26 @@ module RelationalExporter
|
|
|
36
36
|
max_associations = {}
|
|
37
37
|
|
|
38
38
|
::CSV.open('/tmp/test.csv', 'wb', headers: true) do |csv|
|
|
39
|
-
main_klass.
|
|
39
|
+
main_klass.find_all_by_scope(output_config.output.scope.as_json).find_in_batches do |batch|
|
|
40
40
|
batch.each do |single|
|
|
41
41
|
if block_given?
|
|
42
42
|
yield single
|
|
43
|
+
|
|
44
|
+
return unless single
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
row = []
|
|
46
48
|
|
|
47
49
|
# Add main record headers
|
|
48
|
-
|
|
50
|
+
if !main_klass.active_model_serializer.blank?
|
|
51
|
+
main_attributes = main_klass.active_model_serializer.new(single).as_json(root: false) rescue nil
|
|
52
|
+
elsif defined?(BaseSerializer)
|
|
53
|
+
main_attributes = BaseSerializer.new(single).as_json(root: false) rescue nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
main_attributes = single.attributes if main_attributes.nil?
|
|
57
|
+
|
|
58
|
+
main_attributes.each do |field, value|
|
|
49
59
|
header_row << [main_klass.to_s.underscore, field].join('_').classify if csv.header_row?
|
|
50
60
|
row << value
|
|
51
61
|
end
|
|
@@ -98,7 +108,6 @@ module RelationalExporter
|
|
|
98
108
|
csv << header_row if csv.header_row?
|
|
99
109
|
if row.count != header_row.count
|
|
100
110
|
puts "OH SHIT, this row is not right!"
|
|
101
|
-
byebug
|
|
102
111
|
end
|
|
103
112
|
csv << row
|
|
104
113
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relational_exporter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Hammond
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: hashie
|