insights_export 0.2.2 → 0.2.3
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 -2
- data/lib/insights_export/configuration.rb +2 -2
- data/lib/insights_export/export_models.rb +14 -8
- data/lib/insights_export/version.rb +1 -1
- 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: e98d01f8283e0013cf0deb2d300e0a46de25838b
|
4
|
+
data.tar.gz: 942b09cf743334413456faad9a53dec3666e9c84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 663618afbb6a0ef01aa5f6926397bf4a732e6fa551802c8bf55f054a681409d61c30c39f8c567529349d5f132ea554f8b4fd0b090acc4790cd226bb5e7366b65
|
7
|
+
data.tar.gz: da7917ef0e8bbfa585934080ac41256bbdb293fb79fedcb9a9cb7327eb2f01e6d0aeb8bc6fb085ae5ab2039e6fabf2429b7476031d678ec7aa311e400a0203c2
|
data/README.md
CHANGED
@@ -12,11 +12,11 @@ InsightsExport.configure do |config|
|
|
12
12
|
config.export_path = "#{Rails.root}/config/insights.yml"
|
13
13
|
|
14
14
|
# Export only models in this list
|
15
|
-
# Array of strings to filter or blank to export all.
|
15
|
+
# Array of strings or regexps to filter or blank to export all.
|
16
16
|
config.only_models = []
|
17
17
|
|
18
18
|
# Exclude these models from the export
|
19
|
-
# Array of strings to filter or blank to export all.
|
19
|
+
# Array of strings or regexps to filter or blank to export all.
|
20
20
|
config.except_models = []
|
21
21
|
|
22
22
|
# Print a backtrace when the export throws an exception.
|
@@ -5,11 +5,11 @@ module InsightsExport
|
|
5
5
|
attr_accessor :export_path
|
6
6
|
|
7
7
|
# Export only models in this list
|
8
|
-
# Array of strings to filter or
|
8
|
+
# Array of strings or regexps to filter or blank to export all.
|
9
9
|
attr_accessor :only_models
|
10
10
|
|
11
11
|
# Exclude these models from the export
|
12
|
-
# Array of strings to filter or
|
12
|
+
# Array of strings or regexps to filter or blank to export all.
|
13
13
|
attr_accessor :except_models
|
14
14
|
|
15
15
|
# Print a backtrace when the export throws an exception.
|
@@ -53,28 +53,35 @@ module InsightsExport
|
|
53
53
|
|
54
54
|
models = ActiveRecord::Base.descendants
|
55
55
|
|
56
|
+
# skip all abstract classes (e.g. ApplicationRecord)
|
57
|
+
models = models.reject { |m| m.abstract_class? }
|
58
|
+
|
56
59
|
# models to include
|
57
60
|
only_models = InsightsExport.configuration.only_models
|
58
61
|
if only_models.present?
|
59
|
-
models = models.select { |m|
|
62
|
+
models = models.select { |m| only_models.select { |lm| lm.is_a?(Regexp) ? lm.match(m.to_s) : lm == m.to_s }.present? }
|
60
63
|
end
|
61
64
|
|
62
65
|
# models to exclude
|
63
66
|
except_models = InsightsExport.configuration.except_models
|
64
67
|
if except_models.present?
|
65
|
-
models = models.reject { |m|
|
68
|
+
models = models.reject { |m| except_models.select { |lm| lm.is_a?(Regexp) ? lm.match(m.to_s) : lm == m.to_s }.present? }
|
66
69
|
end
|
67
70
|
|
71
|
+
# sort them
|
72
|
+
models = models.sort_by { |m| m.to_s }
|
73
|
+
|
74
|
+
# cache the strings
|
68
75
|
model_strings = models.map(&:to_s)
|
69
76
|
|
77
|
+
# show that we're doing something
|
78
|
+
puts "InsightsExport: #{model_strings.join(', ')}"
|
79
|
+
|
80
|
+
# this will contain our result
|
70
81
|
return_object = {}
|
71
82
|
|
72
83
|
models.each do |model|
|
73
|
-
|
74
|
-
columns_hash = model.columns_hash
|
75
|
-
rescue
|
76
|
-
next
|
77
|
-
end
|
84
|
+
columns_hash = model.columns_hash
|
78
85
|
|
79
86
|
begin
|
80
87
|
model_structure = {
|
@@ -120,7 +127,6 @@ module InsightsExport
|
|
120
127
|
next unless model_strings.include?(reflection_class)
|
121
128
|
|
122
129
|
if reflection.macro == :belongs_to
|
123
|
-
raise 'Bla bla' if model.to_s == 'Product'
|
124
130
|
# reflection_class # User
|
125
131
|
# reflection.foreign_key # user_id
|
126
132
|
# reflection.association_primary_key # id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insights_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marius Andra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|