tramway-api 1.8.6.8 → 1.8.6.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7afaf17fee7b310b01015af00a05f9d8105bab57ee5c8f2582513088bf07a134
4
- data.tar.gz: 10ccdf3863f5cd527bc5e007e39d2b5512cda862b668d64202583a58a1a01ac4
3
+ metadata.gz: 6ca5bbce598b65c6fb0dec505e188231b9c54d58b0969d051c86d6db6036d20b
4
+ data.tar.gz: ffe9fcb8a71069a74053d894738d61b45b214d232514296cb48323be9cfb3e8f
5
5
  SHA512:
6
- metadata.gz: 60433f37641ba07db8bbd32a55c318a0578df5fe92f5fb77b458a043c4e26b384772dcc744ed11d537a9cb72e8cb9f4f1b13e5cf85246f82f2a9ae33ebcfe311
7
- data.tar.gz: 2ee8ae129c4165fe3ef452a63aea87b00b6115e30f9091adf34ac2f9552b2fbefbb78a68f00cbab2d54a0dc04587938a08f30364950b55d94c9468b329f00764
6
+ metadata.gz: db32e275c1fe0475cc0207b8b43d6789f5d611b5210863389e151a165171645e235d9b7f101a8494035378f9d7eba743c5c84de8b24f83709066ef5e986d50db
7
+ data.tar.gz: 50683c4c9c361680a73faba41569e72d660060e0111e2c6f447b3ae496f59745142712b8291ed292d0de577f1151254a7c523f785e69265cd72c6950a01783c2
@@ -6,9 +6,38 @@ module Tramway
6
6
  include ::Knock::Authenticable
7
7
  protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' }
8
8
  rescue_from ActiveRecord::RecordNotFound, with: :not_found if Rails.env.production?
9
+ before_action :load_application
10
+
11
+ def load_application
12
+ if engine_loaded(request).present?
13
+ build_application_with_engine engine_loaded request
14
+ elsif application_class(request).present?
15
+ @application = application_class(request).camelize.constantize.first
16
+ else
17
+ @application = application_object request
18
+ end
19
+ end
9
20
 
10
21
  private
11
22
 
23
+ def build_application_with_engine(engine_loaded)
24
+ engine_module = "::Tramway::#{engine_loaded.camelize}".constantize
25
+ @application = "#{engine_module}::#{engine_module.application.to_s.camelize}".constantize.first
26
+ @application_engine = engine_loaded
27
+ end
28
+
29
+ def application_class(request)
30
+ Constraints::DomainConstraint.new(request.domain).application_class
31
+ end
32
+
33
+ def engine_loaded(request)
34
+ Constraints::DomainConstraint.new(request.domain).engine_loaded
35
+ end
36
+
37
+ def application_object(request)
38
+ Constraints::DomainConstraint.new(request.domain).application_object
39
+ end
40
+
12
41
  def not_found
13
42
  render json: { data: [] }, status: :not_found
14
43
  end
@@ -4,8 +4,6 @@ module Tramway
4
4
  module Api
5
5
  module V1
6
6
  class ApplicationController < ::Tramway::Api::ApplicationController
7
- before_action :application
8
-
9
7
  def render_errors_for(model)
10
8
  render json: model, status: :unprocessable_entity, serializer: ::Tramway::Api::V1::ErrorSerializer
11
9
  end
@@ -112,7 +110,12 @@ module Tramway
112
110
  protected
113
111
 
114
112
  def application_name
115
- @application.present? ? @application.name : raise('Tramway::Api @application not initialized')
113
+ @application ||= Tramway::Core.application&.model_class&.first || Tramway::Core.application
114
+ begin
115
+ @application.name
116
+ rescue
117
+ raise("Tramway::Api @application not initialized, Tramway::Core.application: #{::Tramway::Core.application}, model_class: #{Tramway::Core.application&.model_class }")
118
+ end
116
119
  end
117
120
 
118
121
  def model_class
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.8.6.8'
5
+ VERSION = '1.8.6.13'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.6.8
4
+ version: 1.8.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers