tramway-api 1.8.3.1 → 1.8.6.2

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: 6ea920d1d95b5d0879e4761b50d32a53ae9cd09425fd7ce6f3c35cc6173821cf
4
- data.tar.gz: 248fc9efe23a6b44db5ce5065fc4e15500c3c387f5c39380b83e677cb750434c
3
+ metadata.gz: 6979a107b8db6db6b03df5744632f5c2c137e65006518dd06dcc6f6d63724971
4
+ data.tar.gz: 46e8a150611e423e37b626cb6a35f16253e5190b38539825eefa260883f261fd
5
5
  SHA512:
6
- metadata.gz: 949028808784d424710d0a72e602eefe85144ef46ffd1cba3a1671ad787fb91c527ae2b52002a5c60ada7c4225c9b853c3ee0f944ccda9ac7d224d086d029402
7
- data.tar.gz: 5ca4783d217ee96ab1aef6be3368dd1a8c0a71233a5b129b30147b34d77f74b868933986bddcb0a12229fc4f9d6454332c7a7a1351f4c883b2be8269223c0023
6
+ metadata.gz: e94d128902e6bd42a59041dc1da3fdc49d968b5abdfad66a3421d515ada393f9de75819413da2ad07f86506a425cf55fa12d98492be42afcaf927937a75f2029
7
+ data.tar.gz: 8d73a6a246a6ce4478dd110e480a7a6394cccc22908a97db136adb1dec2cad0faa7f7670bf840b896ad47e97a4a03f904e7547343f1b09da09e75e660017ceec
@@ -24,13 +24,21 @@ module Tramway
24
24
  private
25
25
 
26
26
  def record
27
- id_method = Tramway::Api.id_method_of(model: model_class) || :uuid
28
- @record = model_class.find_by! id_method => params[:id] if params[:id].present?
27
+ if params[:key].present?
28
+ if other_id_methods_of(model: model_class).include? params[:key]
29
+ @record = model_class.find_by! params[:key] => params[:id] if params[:id].present?
30
+ end
31
+ else
32
+ default_id_method = Tramway::Api.default_id_method_of(model: model_class) || :uuid
33
+ @record = model_class.find_by! default_id_method => params[:id] if params[:id].present?
34
+ end
29
35
  end
30
36
 
31
37
  def records
32
- collection = model_class.active.order(id: :desc).send params[:scope] || :all
33
- collection = collection.full_text_search params[:search] if params[:search]
38
+ active_records = model_class.respond_to?(:active) ? model_class.active : model_class.all
39
+ collection = active_records.order(id: :desc).send params[:scope] || :all
40
+ collection = collection.page(params[:page]).per(params[:per]) if params[:page].present?
41
+ collection = collection.full_text_search params[:search] if params[:search].present?
34
42
  collection
35
43
  end
36
44
 
@@ -6,7 +6,7 @@ class Tramway::Api::V1::ApplicationSerializer < ActiveModel::Serializer
6
6
  attribute :id
7
7
 
8
8
  def id
9
- id_method = Tramway::Api.id_method_of(model: object.class) || :uuid
9
+ id_method = Tramway::Api.default_id_method_of(model: object.class) || :uuid
10
10
  object.send(id_method)
11
11
  end
12
12
 
@@ -91,8 +91,12 @@ module Tramway
91
91
  end)
92
92
  end
93
93
 
94
- def id_method_of(model:)
95
- @@id_methods[model.to_s]
94
+ def other_id_methods_of(model:)
95
+ @@id_methods[model.to_s][:other]
96
+ end
97
+
98
+ def default_id_method_of(model:)
99
+ @@id_methods[model.to_s][:default]
96
100
  end
97
101
  end
98
102
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.8.3.1'
5
+ VERSION = '1.8.6.2'
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.3.1
4
+ version: 1.8.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-19 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers