tramway-api 0.6.1.4 → 1.0

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
  SHA256:
3
- metadata.gz: 5f4ee421b6226fde2a273d9480bb4e81e7840b720dd7ff86a66a2895c298c621
4
- data.tar.gz: 5eccc69cd12ab444285c81ac34b754147ad6eceb96cc3d31af6208c670018025
3
+ metadata.gz: d07afcacc198f08e1e7e92ed759e43ba3151e95ff6522937904d9631ccd406ab
4
+ data.tar.gz: 4fd759870eb393540031cfad68fa6688b55f943a2311fd512e8921b728051326
5
5
  SHA512:
6
- metadata.gz: cc94ad91d04b9e707ef33940f91272ca4fda695addbfd6ea0bc678d8a9c7b3c73a3319ee1dac1dec3c4e0f95d3b5875a396e4c304ea72624622762bb82a5c737
7
- data.tar.gz: 8860799234a30261d62ac4e25d24fc47278dad5bcadd8d9d3e12aec99529abb6669886e4784aac8ddd803ceec05cfbf81aede94dcc6b1b96ee6f1f4deb924907
6
+ metadata.gz: ab119aee00928d27118d5abc9c4db6578e854091de8a5793f76ec2d90b2074fd9c0bfe51ca581ef69316f747d781a668401cacd7fff9370faf8a0d6b4a49bc27
7
+ data.tar.gz: d996d04f382755405b28b4451d805cefcfe5d3cb45f6b0fcf7648f44e30533a03b98fb459b46f5cea25cc412f54cd7d945d907a99cfaab23dcac7635c31a8139
@@ -1,5 +1,8 @@
1
1
  module Tramway::Api::V1
2
2
  class RecordsController < ::Tramway::Api::V1::ApplicationController
3
+ before_action :check_available_model_class
4
+ before_action :check_available_model_action
5
+
3
6
  def index
4
7
  records = model_class.active.order(id: :desc).send params[:scope] || :all
5
8
  render json: records,
@@ -31,8 +34,18 @@ module Tramway::Api::V1
31
34
 
32
35
  private
33
36
 
37
+ def check_available_model_class
38
+ head :unprocessable_entity and return unless model_class
39
+ end
40
+
41
+ def check_available_model_action
42
+ head :unprocessable_entity and return unless action_name.in? Tramway::Api.available_models[model_class.to_s].map(&:to_s)
43
+ end
44
+
34
45
  def model_class
35
- params[:model].constantize
46
+ if params[:model].to_s.in? ::Tramway::Api.available_models.keys.map(&:to_s)
47
+ params[:model].constantize
48
+ end
36
49
  end
37
50
 
38
51
  def decorator_class(model_name = nil)
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '0.6.1.4'
3
+ VERSION = '1.0'
4
4
  end
5
5
  end
data/lib/tramway/api.rb CHANGED
@@ -10,6 +10,18 @@ module Tramway
10
10
  def user_based_model=(model_class)
11
11
  @@user_based_model = model_class
12
12
  end
13
+
14
+ def set_available_models(**models)
15
+ @@available_models ||= {}
16
+ models = models.reduce({}) do |hash, pair|
17
+ hash.merge! pair[0].to_s.camelize => pair[1]
18
+ end
19
+ @@available_models.merge! models
20
+ end
21
+
22
+ def available_models
23
+ @@available_models ||= {}
24
+ end
13
25
  end
14
26
  end
15
27
  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: 0.6.1.4
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-17 00:00:00.000000000 Z
11
+ date: 2019-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: knock