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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0275933352213c29067036e3cc65d9ea3fff62e4
4
- data.tar.gz: 930ce586cbaff4579665109867e63fb794589363
3
+ metadata.gz: 586585eabfd0c29fb988b7b4311e21510194a8c4
4
+ data.tar.gz: 44b4952693b40f0f44bb400e1ced0b7b003ed0ef
5
5
  SHA512:
6
- metadata.gz: 7ecd7dc823c021918f107fdc3d2653753fcb922e13d57ab8a4a2042ff69881e5c999cecbe39f448fcbb1ead30f63538ff1f4b8943323bf452e50c05fa32fe735
7
- data.tar.gz: c0a1e7acbacf58ec226a902471fc6fadf2e81ed3c35921684320fa6a0fd6bd02fec536fec570b2ec9f01034439df5426b4c843616187ea4a16bc33f9f9411886
6
+ metadata.gz: c6a8af4773c5ad7b71b6c866328d2f40afce872dd6e73b69b7dd38e302f7d79398d3db7a690198b574d5e8f7114b08ccf25e11733b1e90a83b908ae268f1c847
7
+ data.tar.gz: 5b0aaa71b64e6362342cf6b52d3a8f1a0d554a762648e2c09f1f72b0328adfcf8187ce89499235d7eeb402f730f931d4c1085573994f0e1a1673b4c670c34ba7
@@ -78,10 +78,6 @@ module ForestLiana
78
78
  end
79
79
  end
80
80
 
81
- def resource_params
82
- ResourceDeserializer.new(@resource, params[:resource], true).perform
83
- end
84
-
85
81
  def includes(getter)
86
82
  getter.includes.map(&:to_s)
87
83
  end
@@ -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
@@ -24,7 +24,7 @@ module ForestLiana
24
24
  end
25
25
 
26
26
  def resource_params
27
- ResourceDeserializer.new(@resource, @params[:resource], true).perform
27
+ ResourceDeserializer.new(@resource, @params, true).perform
28
28
  end
29
29
 
30
30
  def set_has_many_relationships
@@ -25,7 +25,7 @@ module ForestLiana
25
25
  end
26
26
 
27
27
  def resource_params
28
- ResourceDeserializer.new(@resource, @params[:resource], false).perform
28
+ ResourceDeserializer.new(@resource, @params, false).perform
29
29
  end
30
30
 
31
31
  def has_strong_parameter
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' => 'resources#index'
10
- get ':collection/:id' => 'resources#show'
11
- post ':collection' => 'resources#create'
12
- put ':collection/:id' => 'resources#update'
13
- delete ':collection/:id' => 'resources#destroy'
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
- create_serializers
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 create_serializers
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
 
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.5.12"
2
+ VERSION = "1.5.13"
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.5.12
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-09 00:00:00.000000000 Z
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