forest_liana 1.3.45 → 1.3.46
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/associations_controller.rb +2 -1
- data/app/controllers/forest_liana/resources_controller.rb +5 -3
- data/app/serializers/forest_liana/serializer_factory.rb +12 -10
- data/app/services/forest_liana/resources_getter.rb +3 -1
- data/app/services/forest_liana/schema_adapter.rb +13 -4
- data/app/services/forest_liana/schema_utils.rb +8 -0
- data/lib/forest_liana.rb +2 -0
- data/lib/forest_liana/bootstraper.rb +15 -6
- data/lib/forest_liana/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: 4417439c5b1e59fdcf52126d5d8f7d7a85984620
|
4
|
+
data.tar.gz: 7f020978c76103078c2d955ea58105cc7d905b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0583159be382733ebdd1b70a8f1a795b411906de86141f2b5c802292e0a83bfbd55ac268a64a815124e89cddd3a5967616f3e7e9b512190723be8afaa02fb4
|
7
|
+
data.tar.gz: e96f7df98db3f5e87ab9b957d36bf14b506ed7d14358584df3b297d29bdacbe59d77c09c2aff26c3a4abbcdcbe215be6d2fb1782b07ce0dea24435bb1c7a5130
|
@@ -66,7 +66,8 @@ module ForestLiana
|
|
66
66
|
@association.klass
|
67
67
|
.reflect_on_all_associations
|
68
68
|
.select do |a|
|
69
|
-
|
69
|
+
SchemaUtils.model_included?(a.klass) &&
|
70
|
+
[:belongs_to, :has_and_belongs_to_many].include?(a.macro) &&
|
70
71
|
!a.options[:polymorphic]
|
71
72
|
end
|
72
73
|
.map {|a| a.name.to_s }
|
@@ -62,7 +62,8 @@ module ForestLiana
|
|
62
62
|
def find_resource
|
63
63
|
@resource = SchemaUtils.find_model_from_table_name(params[:collection])
|
64
64
|
|
65
|
-
if @resource.nil? ||
|
65
|
+
if @resource.nil? || !SchemaUtils.model_included?(@resource) ||
|
66
|
+
!@resource.ancestors.include?(ActiveRecord::Base)
|
66
67
|
render serializer: nil, json: {status: 404}, status: :not_found
|
67
68
|
end
|
68
69
|
end
|
@@ -72,8 +73,9 @@ module ForestLiana
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def includes
|
75
|
-
SchemaUtils.one_associations(@resource)
|
76
|
+
SchemaUtils.one_associations(@resource)
|
77
|
+
.select { |a| SchemaUtils.model_included?(a.klass) }
|
78
|
+
.map { |a| a.name.to_s }
|
76
79
|
end
|
77
|
-
|
78
80
|
end
|
79
81
|
end
|
@@ -182,17 +182,19 @@ module ForestLiana
|
|
182
182
|
end
|
183
183
|
|
184
184
|
SchemaUtils.associations(active_record_class).each do |a|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
185
|
+
if SchemaUtils.model_included?(a.klass)
|
186
|
+
serializer.send(serializer_association(a), a.name) {
|
187
|
+
if [:has_one, :belongs_to].include?(a.macro)
|
188
|
+
begin
|
189
|
+
object.send(a.name).try(:reload)
|
190
|
+
rescue ActiveRecord::RecordNotFound
|
191
|
+
nil
|
192
|
+
end
|
193
|
+
else
|
194
|
+
[]
|
191
195
|
end
|
192
|
-
|
193
|
-
|
194
|
-
end
|
195
|
-
}
|
196
|
+
}
|
197
|
+
end
|
196
198
|
end
|
197
199
|
|
198
200
|
# Intercom
|
@@ -173,10 +173,19 @@ module ForestLiana
|
|
173
173
|
def add_associations
|
174
174
|
SchemaUtils.associations(@model).each do |association|
|
175
175
|
begin
|
176
|
-
if
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
# NOTICE: delete the association if the targeted model is excluded.
|
177
|
+
if !SchemaUtils.model_included?(association.klass)
|
178
|
+
field = collection.fields.find do |x|
|
179
|
+
x[:field] == association.foreign_key
|
180
|
+
end
|
181
|
+
|
182
|
+
collection.fields.delete(field) if field
|
183
|
+
# NOTICE: The foreign key exists, so it's a belongsTo relationship.
|
184
|
+
elsif field = column_association(collection, association)
|
185
|
+
field[:reference] = get_ref_for(association)
|
186
|
+
field[:field] = deforeign_key(field[:field])
|
187
|
+
field[:inverseOf] = inverse_of(association)
|
188
|
+
# NOTICE: Create the fields of hasOne, HasMany, … relationships.
|
180
189
|
else
|
181
190
|
collection.fields << get_schema_for_association(association)
|
182
191
|
end
|
data/lib/forest_liana.rb
CHANGED
@@ -13,6 +13,7 @@ module ForestLiana
|
|
13
13
|
mattr_accessor :apimap
|
14
14
|
mattr_accessor :allowed_users
|
15
15
|
mattr_accessor :models
|
16
|
+
mattr_accessor :excluded_models
|
16
17
|
|
17
18
|
# Legacy.
|
18
19
|
mattr_accessor :jwt_signing_key
|
@@ -20,4 +21,5 @@ module ForestLiana
|
|
20
21
|
self.apimap = []
|
21
22
|
self.allowed_users = []
|
22
23
|
self.models = []
|
24
|
+
self.excluded_models = []
|
23
25
|
end
|
@@ -45,9 +45,16 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
|
+
def analyze_model?(model)
|
49
|
+
return model && model.table_exists? && !SchemaUtils.habtm?(model) &&
|
50
|
+
SchemaUtils.model_included?(model)
|
51
|
+
end
|
52
|
+
|
48
53
|
def fetch_models
|
49
|
-
ActiveRecord::Base.subclasses.each do |
|
50
|
-
|
54
|
+
ActiveRecord::Base.subclasses.each do |model|
|
55
|
+
if analyze_model?(model)
|
56
|
+
ForestLiana.models << model
|
57
|
+
end
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
@@ -58,8 +65,9 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
58
65
|
def create_serializers
|
59
66
|
SchemaUtils.tables_names.map do |table_name|
|
60
67
|
model = SchemaUtils.find_model_from_table_name(table_name)
|
61
|
-
|
62
|
-
|
68
|
+
if analyze_model?(model)
|
69
|
+
ForestLiana::SerializerFactory.new.serializer_for(model)
|
70
|
+
end
|
63
71
|
end
|
64
72
|
|
65
73
|
# Monkey patch the find_serializer_class_name method to specify the
|
@@ -76,7 +84,7 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
76
84
|
end
|
77
85
|
|
78
86
|
def check_integrations_setup
|
79
|
-
|
87
|
+
if stripe_integration?
|
80
88
|
if stripe_integration_valid? || stripe_integration_deprecated?
|
81
89
|
ForestLiana.integrations[:stripe][:mapping] =
|
82
90
|
cast_to_array(ForestLiana.integrations[:stripe][:mapping])
|
@@ -100,7 +108,8 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
|
100
108
|
def create_apimap
|
101
109
|
SchemaUtils.tables_names.map do |table_name|
|
102
110
|
model = SchemaUtils.find_model_from_table_name(table_name)
|
103
|
-
|
111
|
+
|
112
|
+
if analyze_model?(model)
|
104
113
|
SchemaAdapter.new(model).perform
|
105
114
|
end
|
106
115
|
end
|
data/lib/forest_liana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_liana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.46
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|