forest_liana 1.5.12 → 1.5.13
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/resources_controller.rb +0 -4
- data/app/controllers/forest_liana/router.rb +32 -0
- data/app/serializers/forest_liana/serializer_factory.rb +2 -0
- data/app/services/forest_liana/controller_factory.rb +32 -0
- data/app/services/forest_liana/resource_creator.rb +1 -1
- data/app/services/forest_liana/resource_updater.rb +1 -1
- data/config/routes.rb +7 -5
- data/lib/forest_liana/bootstraper.rb +3 -2
- data/lib/forest_liana/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 586585eabfd0c29fb988b7b4311e21510194a8c4
|
4
|
+
data.tar.gz: 44b4952693b40f0f44bb400e1ced0b7b003ed0ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6a8af4773c5ad7b71b6c866328d2f40afce872dd6e73b69b7dd38e302f7d79398d3db7a690198b574d5e8f7114b08ccf25e11733b1e90a83b908ae268f1c847
|
7
|
+
data.tar.gz: 5b0aaa71b64e6362342cf6b52d3a8f1a0d554a762648e2c09f1f72b0328adfcf8187ce89499235d7eeb402f730f931d4c1085573994f0e1a1673b4c670c34ba7
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ForestLiana::Router
|
2
|
+
def call(env)
|
3
|
+
params = env['action_dispatch.request.path_parameters']
|
4
|
+
resource = ForestLiana::SchemaUtils.find_model_from_table_name(params[:collection])
|
5
|
+
|
6
|
+
class_name = resource.table_name.classify
|
7
|
+
module_name = class_name.deconstantize
|
8
|
+
|
9
|
+
name = module_name if module_name
|
10
|
+
name += class_name.demodulize
|
11
|
+
|
12
|
+
ctrl_class = "ForestLiana::#{name}Controller".constantize
|
13
|
+
action = nil
|
14
|
+
|
15
|
+
case env['REQUEST_METHOD']
|
16
|
+
when 'GET'
|
17
|
+
if params[:id]
|
18
|
+
action = 'show'
|
19
|
+
else
|
20
|
+
action = 'index'
|
21
|
+
end
|
22
|
+
when 'PUT'
|
23
|
+
action = 'update'
|
24
|
+
when 'POST'
|
25
|
+
action = 'create'
|
26
|
+
when 'DELETE'
|
27
|
+
action = 'delete'
|
28
|
+
end
|
29
|
+
|
30
|
+
ctrl_class.action(action.to_sym).call(env)
|
31
|
+
end
|
32
|
+
end
|
@@ -10,6 +10,8 @@ module ForestLiana
|
|
10
10
|
name = module_name if module_name
|
11
11
|
name += class_name.demodulize
|
12
12
|
|
13
|
+
# NOTICE: Create the serializer in the UserSpace to avoid conflicts with
|
14
|
+
# serializer created from integrations, actions, segments, etc.
|
13
15
|
ForestLiana::UserSpace.const_set("#{name}Serializer", serializer)
|
14
16
|
end
|
15
17
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class ControllerFactory
|
3
|
+
|
4
|
+
def self.define_controller(active_record_class, service)
|
5
|
+
class_name = active_record_class.table_name.classify
|
6
|
+
module_name = class_name.deconstantize
|
7
|
+
|
8
|
+
name = module_name if module_name
|
9
|
+
name += class_name.demodulize
|
10
|
+
|
11
|
+
ForestLiana.const_set("#{name}Controller", service)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_controller_name(active_record_class)
|
15
|
+
class_name = active_record_class.table_name.classify
|
16
|
+
module_name = class_name.deconstantize
|
17
|
+
|
18
|
+
name = module_name if module_name
|
19
|
+
name += class_name.demodulize
|
20
|
+
|
21
|
+
"ForestLiana::#{name}Controller"
|
22
|
+
end
|
23
|
+
|
24
|
+
def controller_for(active_record_class)
|
25
|
+
controller = Class.new(ResourcesController) { }
|
26
|
+
|
27
|
+
ForestLiana::ControllerFactory.define_controller(active_record_class,
|
28
|
+
controller)
|
29
|
+
controller
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
ForestLiana::Engine.routes.draw do
|
2
|
+
router = ForestLiana::Router.new
|
3
|
+
|
2
4
|
# Onboarding
|
3
5
|
get '/' => 'apimaps#index'
|
4
6
|
|
@@ -6,11 +8,11 @@ ForestLiana::Engine.routes.draw do
|
|
6
8
|
post 'sessions' => 'sessions#create'
|
7
9
|
|
8
10
|
# CRUD
|
9
|
-
get ':collection'
|
10
|
-
get ':collection/:id'
|
11
|
-
post ':collection'
|
12
|
-
put ':collection/:id'
|
13
|
-
delete ':collection/:id'
|
11
|
+
get ':collection', to: router
|
12
|
+
get ':collection/:id', to: router
|
13
|
+
post ':collection', to: router
|
14
|
+
put ':collection/:id', to: router
|
15
|
+
delete ':collection/:id', to: router
|
14
16
|
|
15
17
|
# Associations
|
16
18
|
get ':collection/:id/relationships/:association_name' => 'associations#index'
|
@@ -20,7 +20,7 @@ module ForestLiana
|
|
20
20
|
def perform
|
21
21
|
fetch_models
|
22
22
|
check_integrations_setup
|
23
|
-
|
23
|
+
create_factories
|
24
24
|
|
25
25
|
if ForestLiana.env_secret
|
26
26
|
create_apimap
|
@@ -72,11 +72,12 @@ module ForestLiana
|
|
72
72
|
value.is_a?(String) ? [value] : value
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
75
|
+
def create_factories
|
76
76
|
SchemaUtils.tables_names.map do |table_name|
|
77
77
|
model = SchemaUtils.find_model_from_table_name(table_name)
|
78
78
|
if analyze_model?(model)
|
79
79
|
ForestLiana::SerializerFactory.new.serializer_for(model)
|
80
|
+
ForestLiana::ControllerFactory.new.controller_for(model)
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
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.5.
|
4
|
+
version: 1.5.13
|
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-03-
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- app/controllers/forest_liana/associations_controller.rb
|
142
142
|
- app/controllers/forest_liana/intercom_controller.rb
|
143
143
|
- app/controllers/forest_liana/resources_controller.rb
|
144
|
+
- app/controllers/forest_liana/router.rb
|
144
145
|
- app/controllers/forest_liana/sessions_controller.rb
|
145
146
|
- app/controllers/forest_liana/stats_controller.rb
|
146
147
|
- app/controllers/forest_liana/stripe_controller.rb
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- app/serializers/forest_liana/stripe_subscription_serializer.rb
|
167
168
|
- app/services/forest_liana/allowed_users_getter.rb
|
168
169
|
- app/services/forest_liana/belongs_to_updater.rb
|
170
|
+
- app/services/forest_liana/controller_factory.rb
|
169
171
|
- app/services/forest_liana/has_many_associator.rb
|
170
172
|
- app/services/forest_liana/has_many_dissociator.rb
|
171
173
|
- app/services/forest_liana/has_many_getter.rb
|