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 +4 -4
- data/app/controllers/tramway/api/v1/records_controller.rb +14 -1
- data/lib/tramway/api/version.rb +1 -1
- data/lib/tramway/api.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07afcacc198f08e1e7e92ed759e43ba3151e95ff6522937904d9631ccd406ab
|
4
|
+
data.tar.gz: 4fd759870eb393540031cfad68fa6688b55f943a2311fd512e8921b728051326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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].
|
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)
|
data/lib/tramway/api/version.rb
CHANGED
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:
|
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-
|
11
|
+
date: 2019-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knock
|