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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1197ecc6859d426da4304284756562c149d411a2
4
- data.tar.gz: b70fa41d65454624496f6f83b39c793b1b897683
3
+ metadata.gz: 4417439c5b1e59fdcf52126d5d8f7d7a85984620
4
+ data.tar.gz: 7f020978c76103078c2d955ea58105cc7d905b9f
5
5
  SHA512:
6
- metadata.gz: 87acdf552773f941b0f3665281287b30f79110fa787b331e7cefa9d84e2380ac4506db1d96294135d420309fea4e916a7063f59ef33240fa706dbdfba34fddec
7
- data.tar.gz: c283ed7a3619616b353dde7fc0ad60c67e853afbffb30120081f63abe28d891babbd1955dbb14cd82a2d014d4b3eb65d770af08dcfb1e27cb00032c36abd4ed7
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
- [:belongs_to, :has_and_belongs_to_many].include?(a.macro) &&
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? || !@resource.ancestors.include?(ActiveRecord::Base)
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).map {|a| a.name.to_s}
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
- serializer.send(serializer_association(a), a.name) {
186
- if [:has_one, :belongs_to].include?(a.macro)
187
- begin
188
- object.send(a.name).try(:reload)
189
- rescue ActiveRecord::RecordNotFound
190
- nil
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
- else
193
- []
194
- end
195
- }
196
+ }
197
+ end
196
198
  end
197
199
 
198
200
  # Intercom
@@ -77,7 +77,9 @@ module ForestLiana
77
77
  end
78
78
 
79
79
  def includes
80
- SchemaUtils.one_associations(@resource).map(&:name)
80
+ SchemaUtils.one_associations(@resource)
81
+ .select { |a| SchemaUtils.model_included?(a.klass) }
82
+ .map(&:name)
81
83
  end
82
84
 
83
85
  def offset
@@ -173,10 +173,19 @@ module ForestLiana
173
173
  def add_associations
174
174
  SchemaUtils.associations(@model).each do |association|
175
175
  begin
176
- if schema = column_association(collection, association)
177
- schema[:reference] = get_ref_for(association)
178
- schema[:field] = deforeign_key(schema[:field])
179
- schema[:inverseOf] = inverse_of(association)
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
@@ -48,6 +48,14 @@ module ForestLiana
48
48
  end
49
49
  end
50
50
  end
51
+
52
+ def self.model_included?(model)
53
+ ForestLiana.excluded_models.exclude?(model)
54
+ end
55
+
56
+ def self.habtm?(model)
57
+ model.name.starts_with?('HABTM')
58
+ end
51
59
  end
52
60
  end
53
61
 
@@ -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 |subclass|
50
- ForestLiana.models << subclass
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
- ForestLiana::SerializerFactory.new.serializer_for(model) if \
62
- model.try(:table_exists?)
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
- if stripe_integration?
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
- if model.try(:table_exists?)
111
+
112
+ if analyze_model?(model)
104
113
  SchemaAdapter.new(model).perform
105
114
  end
106
115
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.3.45"
2
+ VERSION = "1.3.46"
3
3
  end
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.45
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-14 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails