forest_liana 1.6.5 → 1.6.6
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/app/controllers/forest_liana/associations_controller.rb +1 -1
- data/app/controllers/forest_liana/devise_controller.rb +1 -1
- data/app/controllers/forest_liana/resources_controller.rb +1 -1
- data/app/controllers/forest_liana/router.rb +3 -2
- data/app/controllers/forest_liana/stats_controller.rb +2 -1
- data/app/serializers/forest_liana/serializer_factory.rb +10 -10
- data/app/services/forest_liana/controller_factory.rb +2 -2
- data/app/services/forest_liana/schema_adapter.rb +6 -6
- data/app/services/forest_liana/schema_utils.rb +7 -7
- data/app/services/forest_liana/stripe_bank_accounts_getter.rb +1 -1
- data/app/services/forest_liana/stripe_cards_getter.rb +1 -1
- data/app/services/forest_liana/stripe_invoices_getter.rb +1 -1
- data/app/services/forest_liana/stripe_payments_getter.rb +1 -1
- data/app/services/forest_liana/stripe_subscriptions_getter.rb +1 -1
- data/lib/forest_liana.rb +10 -1
- data/lib/forest_liana/bootstraper.rb +14 -0
- data/lib/forest_liana/collection.rb +2 -1
- 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: ce8dc1b8cf30b7f5734362bcd69b549d990a2b71
|
4
|
+
data.tar.gz: 5aca5a5e19a92349d6503a0f8b3b72b3cbc40ab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e7c2b6a3afbe0c786ac13efa22874e400cedbe85f8e9fb7ff076d83335f49db441239effcf598b705b37320a72057d7b0f6ac697f51b3040f335b209774239c
|
7
|
+
data.tar.gz: 1567b0fe318660845cf31b843eaafe32ab09d79ab061cd526cfeb3e863900a35f273e23c9bd4d3addf8eca1c83ca8537bbc1b99a9ad5c6134f855daedc8f577e
|
@@ -42,7 +42,7 @@ module ForestLiana
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def find_resource
|
45
|
-
@resource = SchemaUtils.
|
45
|
+
@resource = SchemaUtils.find_model_from_collection_name(params[:collection])
|
46
46
|
|
47
47
|
if @resource.nil? || !@resource.ancestors.include?(ActiveRecord::Base)
|
48
48
|
render serializer: nil, json: {status: 404}, status: :not_found
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class DeviseController < ForestLiana::ApplicationController
|
3
3
|
def change_password
|
4
|
-
resource = SchemaUtils.
|
4
|
+
resource = SchemaUtils.find_model_from_collection_name(
|
5
5
|
params['data']['attributes']['collection_name'])
|
6
6
|
|
7
7
|
user = resource.find(params['data']['attributes']['ids'].first)
|
@@ -72,7 +72,7 @@ module ForestLiana
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def find_resource
|
75
|
-
@resource = SchemaUtils.
|
75
|
+
@resource = SchemaUtils.find_model_from_collection_name(params[:collection])
|
76
76
|
|
77
77
|
if @resource.nil? || !SchemaUtils.model_included?(@resource) ||
|
78
78
|
!@resource.ancestors.include?(ActiveRecord::Base)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class ForestLiana::Router
|
2
2
|
def call(env)
|
3
3
|
params = env['action_dispatch.request.path_parameters']
|
4
|
-
resource = ForestLiana::SchemaUtils.
|
4
|
+
resource = ForestLiana::SchemaUtils.find_model_from_collection_name(
|
5
|
+
params[:collection])
|
5
6
|
|
6
|
-
class_name = resource.
|
7
|
+
class_name = ForestLiana.name_for(resource).classify
|
7
8
|
module_name = class_name.deconstantize
|
8
9
|
|
9
10
|
name = module_name if module_name
|
@@ -27,7 +27,8 @@ module ForestLiana
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def find_resource
|
30
|
-
@resource = SchemaUtils.
|
30
|
+
@resource = SchemaUtils.find_model_from_collection_name(
|
31
|
+
params[:collection])
|
31
32
|
|
32
33
|
if @resource.nil? || !@resource.ancestors.include?(ActiveRecord::Base)
|
33
34
|
render json: {status: 404}, status: :not_found, serializer: nil
|
@@ -4,7 +4,7 @@ module ForestLiana
|
|
4
4
|
class SerializerFactory
|
5
5
|
|
6
6
|
def self.define_serializer(active_record_class, serializer)
|
7
|
-
class_name = active_record_class.
|
7
|
+
class_name = ForestLiana.name_for(active_record_class).classify
|
8
8
|
module_name = class_name.deconstantize
|
9
9
|
|
10
10
|
name = module_name if module_name
|
@@ -46,7 +46,7 @@ module ForestLiana
|
|
46
46
|
elsif active_record_class == ForestLiana::Model::Segment
|
47
47
|
"ForestLiana::SegmentSerializer"
|
48
48
|
else
|
49
|
-
class_name = active_record_class.
|
49
|
+
class_name = ForestLiana.name_for(active_record_class).classify
|
50
50
|
module_name = class_name.deconstantize
|
51
51
|
|
52
52
|
name = module_name if module_name
|
@@ -65,7 +65,7 @@ module ForestLiana
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def type
|
68
|
-
object.class.
|
68
|
+
ForestLiana.name_for(object.class).demodulize
|
69
69
|
end
|
70
70
|
|
71
71
|
def format_name(attribute_name)
|
@@ -86,27 +86,27 @@ module ForestLiana
|
|
86
86
|
# Has many smart field
|
87
87
|
current = self.has_many_relationships[attribute_name]
|
88
88
|
if current.try(:[], :options).try(:[], :name) == attribute_name
|
89
|
-
ret[:href] = "/forest/#{object.class
|
89
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/#{attribute_name}"
|
90
90
|
return ret
|
91
91
|
end
|
92
92
|
|
93
93
|
if intercom_integration?
|
94
94
|
case attribute_name
|
95
95
|
when :intercom_conversations
|
96
|
-
ret[:href] = "/forest/#{object.class
|
96
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/intercom_conversations"
|
97
97
|
when :intercom_attributes
|
98
|
-
ret[:href] = "/forest/#{object.class
|
98
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/intercom_attributes"
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
if stripe_integration?
|
103
103
|
case attribute_name
|
104
104
|
when :stripe_payments
|
105
|
-
ret[:href] = "/forest/#{object.class
|
105
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_payments"
|
106
106
|
when :stripe_invoices
|
107
|
-
ret[:href] = "/forest/#{object.class
|
107
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_invoices"
|
108
108
|
when :stripe_cards
|
109
|
-
ret[:href] = "/forest/#{object.class
|
109
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/stripe_cards"
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -118,7 +118,7 @@ module ForestLiana
|
|
118
118
|
|
119
119
|
SchemaUtils.many_associations(object.class).each do |a|
|
120
120
|
if a.name == attribute_name
|
121
|
-
ret[:href] = "/forest/#{object.class
|
121
|
+
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/relationships/#{attribute_name}"
|
122
122
|
end
|
123
123
|
end
|
124
124
|
rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError
|
@@ -2,7 +2,7 @@ module ForestLiana
|
|
2
2
|
class ControllerFactory
|
3
3
|
|
4
4
|
def self.define_controller(active_record_class, service)
|
5
|
-
class_name = active_record_class.
|
5
|
+
class_name = ForestLiana.name_for(active_record_class).classify
|
6
6
|
module_name = class_name.deconstantize
|
7
7
|
|
8
8
|
name = module_name if module_name
|
@@ -12,7 +12,7 @@ module ForestLiana
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.get_controller_name(active_record_class)
|
15
|
-
class_name = active_record_class.
|
15
|
+
class_name = ForestLiana.name_for(active_record_class).classify
|
16
16
|
module_name = class_name.deconstantize
|
17
17
|
|
18
18
|
name = module_name if module_name
|
@@ -50,12 +50,12 @@ module ForestLiana
|
|
50
50
|
def collection
|
51
51
|
@collection ||= begin
|
52
52
|
collection = ForestLiana.apimap.find do |x|
|
53
|
-
x.name.to_s == @model
|
53
|
+
x.name.to_s == ForestLiana.name_for(@model)
|
54
54
|
end
|
55
55
|
|
56
56
|
if collection.blank?
|
57
57
|
collection = ForestLiana::Model::Collection.new({
|
58
|
-
name: @model
|
58
|
+
name: ForestLiana.name_for(@model),
|
59
59
|
fields: []
|
60
60
|
})
|
61
61
|
|
@@ -80,7 +80,7 @@ module ForestLiana
|
|
80
80
|
if ForestLiana.integrations.try(:[], :intercom)
|
81
81
|
.try(:[], :mapping).try(:include?, @model.name)
|
82
82
|
|
83
|
-
model_name = @model
|
83
|
+
model_name = ForestLiana.name_for(@model)
|
84
84
|
|
85
85
|
collection.fields << {
|
86
86
|
field: :intercom_conversations,
|
@@ -110,7 +110,7 @@ module ForestLiana
|
|
110
110
|
.select { |mapping| mapping.split('.')[0] == @model.name }
|
111
111
|
.size > 0
|
112
112
|
|
113
|
-
model_name = @model
|
113
|
+
model_name = ForestLiana.name_for(@model)
|
114
114
|
|
115
115
|
collection.fields << {
|
116
116
|
field: :stripe_payments,
|
@@ -235,7 +235,7 @@ module ForestLiana
|
|
235
235
|
{
|
236
236
|
field: association.name.to_s,
|
237
237
|
type: get_type_for_association(association),
|
238
|
-
reference: "#{association.klass
|
238
|
+
reference: "#{ForestLiana.name_for(association.klass)}.id",
|
239
239
|
inverseOf: inverse_of(association)
|
240
240
|
}
|
241
241
|
end
|
@@ -298,7 +298,7 @@ module ForestLiana
|
|
298
298
|
if association.options[:polymorphic] == true
|
299
299
|
'*.id'
|
300
300
|
else
|
301
|
-
"#{association.klass.
|
301
|
+
"#{ForestLiana.name_for(association.klass).underscore}.id"
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
@@ -19,13 +19,13 @@ module ForestLiana
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
22
|
+
def self.find_model_from_collection_name(collection_name)
|
23
23
|
model = nil
|
24
24
|
|
25
25
|
ForestLiana.models.each do |subclass|
|
26
26
|
if subclass.abstract_class?
|
27
|
-
model = self.find_model_from_abstract_class(subclass,
|
28
|
-
elsif subclass
|
27
|
+
model = self.find_model_from_abstract_class(subclass, collection_name)
|
28
|
+
elsif ForestLiana.name_for(subclass) == collection_name
|
29
29
|
model = subclass.base_class
|
30
30
|
end
|
31
31
|
|
@@ -45,12 +45,12 @@ module ForestLiana
|
|
45
45
|
association.options[:polymorphic]
|
46
46
|
end
|
47
47
|
|
48
|
-
def self.find_model_from_abstract_class(abstract_class,
|
48
|
+
def self.find_model_from_abstract_class(abstract_class, collection_name)
|
49
49
|
abstract_class.subclasses.find do |subclass|
|
50
50
|
if subclass.abstract_class?
|
51
|
-
return self.
|
51
|
+
return self.find_model_from_collection_name(subclass, collection_name)
|
52
52
|
else
|
53
|
-
subclass
|
53
|
+
ForestLiana.name_for(subclass) == collection_name
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -75,7 +75,7 @@ module ForestLiana
|
|
75
75
|
begin
|
76
76
|
parent = model.try(:superclass)
|
77
77
|
|
78
|
-
if
|
78
|
+
if ForestLiana.name_for(parent)
|
79
79
|
inheritance_column = parent.columns.find do |c|
|
80
80
|
(parent.inheritance_column && c.name == parent.inheritance_column)\
|
81
81
|
|| c.name == 'type'
|
@@ -79,7 +79,7 @@ module ForestLiana
|
|
79
79
|
def field
|
80
80
|
ForestLiana.integrations[:stripe][:mapping].select { |value|
|
81
81
|
value.split('.')[0] == ForestLiana::SchemaUtils
|
82
|
-
.
|
82
|
+
.find_model_from_collection_name(@params[:collection]).try(:name)
|
83
83
|
}.first.split('.')[1]
|
84
84
|
end
|
85
85
|
end
|
@@ -79,7 +79,7 @@ module ForestLiana
|
|
79
79
|
def field
|
80
80
|
ForestLiana.integrations[:stripe][:mapping].select { |value|
|
81
81
|
value.split('.')[0] == ForestLiana::SchemaUtils
|
82
|
-
.
|
82
|
+
.find_model_from_collection_name(@params[:collection]).try(:name)
|
83
83
|
}.first.split('.')[1]
|
84
84
|
end
|
85
85
|
end
|
@@ -88,7 +88,7 @@ module ForestLiana
|
|
88
88
|
def field
|
89
89
|
ForestLiana.integrations[:stripe][:mapping].select { |value|
|
90
90
|
value.split('.')[0] == ForestLiana::SchemaUtils
|
91
|
-
.
|
91
|
+
.find_model_from_collection_name(@params[:collection]).try(:name)
|
92
92
|
}.first.split('.')[1]
|
93
93
|
end
|
94
94
|
end
|
@@ -86,7 +86,7 @@ module ForestLiana
|
|
86
86
|
def field
|
87
87
|
ForestLiana.integrations[:stripe][:mapping].select { |value|
|
88
88
|
value.split('.')[0] == ForestLiana::SchemaUtils
|
89
|
-
.
|
89
|
+
.find_model_from_collection_name(@params[:collection]).try(:name)
|
90
90
|
}.first.split('.')[1]
|
91
91
|
end
|
92
92
|
end
|
@@ -90,7 +90,7 @@ module ForestLiana
|
|
90
90
|
def field
|
91
91
|
ForestLiana.integrations[:stripe][:mapping].select { |value|
|
92
92
|
value.split('.')[0] == ForestLiana::SchemaUtils
|
93
|
-
.
|
93
|
+
.find_model_from_collection_name(@params[:collection]).try(:name)
|
94
94
|
}.first.split('.')[1]
|
95
95
|
end
|
96
96
|
end
|
data/lib/forest_liana.rb
CHANGED
@@ -20,6 +20,7 @@ module ForestLiana
|
|
20
20
|
mattr_accessor :excluded_models
|
21
21
|
mattr_accessor :included_models
|
22
22
|
mattr_accessor :user_class_name
|
23
|
+
mattr_accessor :names_overriden
|
23
24
|
|
24
25
|
self.apimap = []
|
25
26
|
self.allowed_users = []
|
@@ -27,8 +28,16 @@ module ForestLiana
|
|
27
28
|
self.excluded_models = []
|
28
29
|
self.included_models = []
|
29
30
|
self.user_class_name = nil
|
31
|
+
self.names_overriden = {}
|
30
32
|
|
31
33
|
def self.schema_for_resource resource
|
32
|
-
self.apimap.find
|
34
|
+
self.apimap.find do |collection|
|
35
|
+
SchemaUtils.find_model_from_collection_name(collection.name)
|
36
|
+
.try(:table_name) == resource.table_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.name_for(model)
|
41
|
+
self.names_overriden[model] || model.try(:table_name)
|
33
42
|
end
|
34
43
|
end
|
@@ -20,6 +20,7 @@ module ForestLiana
|
|
20
20
|
def perform
|
21
21
|
fetch_models
|
22
22
|
check_integrations_setup
|
23
|
+
namespace_duplicated_models
|
23
24
|
create_factories
|
24
25
|
|
25
26
|
if ForestLiana.env_secret
|
@@ -100,6 +101,19 @@ module ForestLiana
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
104
|
+
def namespace_duplicated_models
|
105
|
+
ForestLiana.models
|
106
|
+
.group_by {|model| model.table_name}
|
107
|
+
.select {|table_name, models| models.length > 1}
|
108
|
+
.try(:each) do |table_name, models|
|
109
|
+
models.each do |model|
|
110
|
+
ForestLiana.names_overriden[model] =
|
111
|
+
"#{model.name.deconstantize.downcase}__#{model.table_name}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
103
117
|
def create_apimap
|
104
118
|
ForestLiana.models.map do |model|
|
105
119
|
if analyze_model?(model)
|
@@ -100,7 +100,8 @@ module ForestLiana::Collection
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def active_record_class
|
103
|
-
ForestLiana::SchemaUtils.
|
103
|
+
ForestLiana::SchemaUtils.find_model_from_collection_name(
|
104
|
+
self.collection_name)
|
104
105
|
end
|
105
106
|
|
106
107
|
def serializer_name
|
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.6.
|
4
|
+
version: 1.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|