insights_export 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b3cc11cb225f05541df399578423bb370fad699
4
- data.tar.gz: bbc9af0241b380c0f91d99a425016e3ccf5e87c9
3
+ metadata.gz: e98d01f8283e0013cf0deb2d300e0a46de25838b
4
+ data.tar.gz: 942b09cf743334413456faad9a53dec3666e9c84
5
5
  SHA512:
6
- metadata.gz: b7ddc9fffe0f31cef0d90059e648eb0f7b21ab153b1056525c1868fc4b989b35f6743756ec990dc088e76cc530c5ce3f4d490e71c122e18cd73240f534809e1e
7
- data.tar.gz: b5c8921153667c08f4e5754703781c5700d5ef684b67f209a8fb76e2587933ad2493599eabd9626ba42e46155d17315533fb78e6cd29aadb572f237e77b7783f
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 empty array to export all.
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 empty array to export all.
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| m.to_s.in?(only_models) }
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| m.to_s.in?(except_models) }
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
- begin
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
@@ -1,3 +1,3 @@
1
1
  module InsightsExport
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
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.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-06 00:00:00.000000000 Z
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake