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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 812375c407e516d9335f9de5ef56b1472bd67e2a
4
- data.tar.gz: 05079ba3387f1a94910da2d2e9338883156e3bbf
3
+ metadata.gz: 93369bce5ffa225e191684a1b1655bede21b40ce
4
+ data.tar.gz: 4b811e535dedd706361921e85d204938436c8912
5
5
  SHA512:
6
- metadata.gz: bec4595a08715fb900cf95e6c3b7b647b8b5a3e996068e75aa9f19d39d06c00857a1af22480c45f230e103e892efadaba06349d8147872b2b5af7fe43a0cbdba
7
- data.tar.gz: 70b0fe2eebfc33cfef4d5ceb2096a20a0dd7f03af68e9f51a117228a886940d05bd27ff5f536c1e2971f9337d2d5e3e072e46cb52ffcf5fbb86bcd67b3d57940
6
+ metadata.gz: 9eae62da777df4f3991a206323d80351cced31ff9d86a2547d884ea1c92058c16198ded18819f877769fdd9983145b960ea0a9dd063001e2831e310c3506e83e
7
+ data.tar.gz: 5c2d7546a87f69f34a481873769b619bab48cf6cbc751f5b75162f703ff88e1a9eb28928a8428832e5efa8af62a2e97b6bdf6ae185df4e9c97617ffc10ce625e
@@ -1,3 +1,3 @@
1
1
  module RelationalExporter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.all.find_in_batches do |batch|
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
- single.attributes.each do |field, value|
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.1
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-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie