insights_export 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/lib/insights_export/configuration.rb +33 -0
- data/lib/insights_export/export_models.rb +17 -1
- data/lib/insights_export/version.rb +1 -1
- data/lib/insights_export.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 246b8d0d36e3a7edcfcefd0eee4905267b413bdf
|
4
|
+
data.tar.gz: 5130abb2f2042dfa39b67fd10183fd673ddce823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6317ec7dbd143bf3739a5d4757dd8470e8f93b09ae630d05b313c35545d36a45561fb99580f578596fca0f8a7e6d9906208ba3e23fa2e1e85e2132740e96229
|
7
|
+
data.tar.gz: b8174fbec18cb8090db116908fe8cab72e94ffbc8a0be8ff51e8701569f17e02f452b22c1dfa32335bfd31cc02b6da461e0fffd827f8cde4c916fb7aef54616c
|
data/README.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
1
|
# insights_export
|
2
2
|
|
3
|
-
For use with [insights](https://github.com/mariusandra/insights)
|
3
|
+
For use with [insights](https://github.com/mariusandra/insights). Read the installation instructions [here](https://github.com/mariusandra/insights).
|
4
|
+
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
To configure the gem, create a file like `config/initializers/insights_export.rb` with this content:
|
8
|
+
|
9
|
+
```rb
|
10
|
+
InsightsExport.configure do |config|
|
11
|
+
# The path to the export file
|
12
|
+
# Defaults to "#{Rails.root}/config/insights.yml"
|
13
|
+
config.export_path = "#{Rails.root}/config/insights2.yml"
|
14
|
+
|
15
|
+
# Export only models in this list
|
16
|
+
# Array of strings to filter or blank to export all.
|
17
|
+
config.only_models = []
|
18
|
+
|
19
|
+
# Exclude these models from the export
|
20
|
+
# Array of strings to filter or blank to export all.
|
21
|
+
config.except_models = []
|
22
|
+
end
|
23
|
+
```
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module InsightsExport
|
2
|
+
class Configuration
|
3
|
+
# The path to the export file
|
4
|
+
# Defaults to "#{Rails.root}/config/insights.yml"
|
5
|
+
attr_accessor :export_path
|
6
|
+
|
7
|
+
# Export only models in this list
|
8
|
+
# Array of strings to filter or empty array to export all.
|
9
|
+
attr_accessor :only_models
|
10
|
+
|
11
|
+
# Exclude these models from the export
|
12
|
+
# Array of strings to filter or empty array to export all.
|
13
|
+
attr_accessor :except_models
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@export_path = "#{Rails.root}/config/insights.yml"
|
17
|
+
@only_models = []
|
18
|
+
@except_models = []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configuration=(config)
|
27
|
+
@configuration = config
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.configure
|
31
|
+
yield configuration
|
32
|
+
end
|
33
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module InsightsExport
|
2
2
|
class ExportModels
|
3
3
|
def self.config_file
|
4
|
-
|
4
|
+
InsightsExport.configuration.export_path
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.load
|
@@ -53,6 +53,20 @@ module InsightsExport
|
|
53
53
|
|
54
54
|
models = ActiveRecord::Base.descendants
|
55
55
|
|
56
|
+
# models to include
|
57
|
+
only_models = InsightsExport.configuration.only_models
|
58
|
+
if only_models.present?
|
59
|
+
models = models.select { |m| m.to_s.in?(only_models) }
|
60
|
+
end
|
61
|
+
|
62
|
+
# models to exclude
|
63
|
+
except_models = InsightsExport.configuration.except_models
|
64
|
+
if except_models.present?
|
65
|
+
models = models.reject { |m| m.to_s.in?(except_models) }
|
66
|
+
end
|
67
|
+
|
68
|
+
model_strings = models.map(&:to_s)
|
69
|
+
|
56
70
|
models.map do |model|
|
57
71
|
begin
|
58
72
|
columns_hash = model.columns_hash
|
@@ -102,6 +116,8 @@ module InsightsExport
|
|
102
116
|
}
|
103
117
|
|
104
118
|
model.reflections.each do |association_name, reflection|
|
119
|
+
next unless model_strings.include?(reflection.class_name)
|
120
|
+
|
105
121
|
if reflection.macro == :belongs_to
|
106
122
|
# reflection.class_name # User
|
107
123
|
# reflection.foreign_key # user_id
|
data/lib/insights_export.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- insights_export.gemspec
|
38
38
|
- lib/insights_export.rb
|
39
|
+
- lib/insights_export/configuration.rb
|
39
40
|
- lib/insights_export/export_models.rb
|
40
41
|
- lib/insights_export/railtie.rb
|
41
42
|
- lib/insights_export/version.rb
|