tramway-api 1.8.6.1 → 1.8.6.6

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: '099a8be3907e271356fd1862d50e6b45f91a611baf481dc719a2fbf74d0f2277'
4
- data.tar.gz: 3b1a738428b4f0c147b4a4b3911fd80f84e9c3cfce6deed23eb7b66e2999947d
3
+ metadata.gz: c073884812f246c0b76d5367b19c2f1348dbe8539286b08027487e716e2dd959
4
+ data.tar.gz: d49ede45c33a877a8deea8dcb9fb0285d1ef0d2154cd9e44109b0801e0280e4c
5
5
  SHA512:
6
- metadata.gz: 2c4467c3a491b5a6154e4d67e302d412444f0dfc96087a8778e303350635b8928ac3820e137b5cde37adcd886b561706e27af3d5c543240901cbccc8ab7b148c
7
- data.tar.gz: 583afa7ea8e70fbda137a4bd701cfb37369fdc4944114347dd889911ffb6f1da3c3377ecf3497931d41cd2f9fbc52fd1596ca95c097acdf46eda6ba3bf2d740c
6
+ metadata.gz: a26de6225b11387505eac518f7d2ddec5ea0d3070007f6838e4d5192e9296793eed0f2c38af2a445286fffc0fc4f2bdb65fb449f32a6c64e4be13d2c51ce1270
7
+ data.tar.gz: 33e67a11a31f45d4413d8f24a8f7a75075a38f74f3f99cb0456be838f59ccf38acf0f3cf4649cc27c6fb054e0f4349ff0b78fbf241a66204650685ab7f95d4b7
data/README.md CHANGED
@@ -105,10 +105,18 @@ To choose your own public ID method, just add this line to:
105
105
  *config/initializers/tramway.rb*
106
106
 
107
107
  ```ruby
108
- Tramway::Api.id_methods_of(User => :id)
108
+ Tramway::Api.id_methods_of(User => { default: :id })
109
109
  ```
110
110
  If you want to use `uuid` by default, please, add it to your models
111
111
 
112
+ ### Also, you can add array of secondary methods as IDs, but you'll need to add their names to a request
113
+
114
+ ```ruby
115
+ Tramway::Api.id_methods_of(User => { default: id, other: :email }
116
+ ```
117
+
118
+ in this case your request will look like this `/api/v1/records/someEmail@mail.com?model=User&key=email`
119
+
112
120
  #### Add generating uuid by default to every model, that is accessible by API
113
121
 
114
122
  *db/migrate/add_uuid_to_some_model.rb*
@@ -383,6 +391,8 @@ end
383
391
 
384
392
  You have your records in JSON API spec.
385
393
 
394
+ You also able to use pagination, provided by `kaminari`
395
+
386
396
  ### Create
387
397
 
388
398
  *config/initializers/tramway.rb*
@@ -25,7 +25,7 @@ module Tramway
25
25
 
26
26
  def record
27
27
  if params[:key].present?
28
- if ids_methods_of(model: model_class).include? params[:key]
28
+ if Tramway::Api.other_id_methods_of(model: model_class).include? params[:key].to_sym
29
29
  @record = model_class.find_by! params[:key] => params[:id] if params[:id].present?
30
30
  end
31
31
  else
@@ -16,25 +16,29 @@ class Tramway::Api::V1::ErrorSerializer < ActiveModel::Serializer
16
16
  def error_messages(object, path = []) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
17
17
  error_messages = {}
18
18
 
19
- object.errors.messages.each do |name, messages|
20
- error_messages.merge!((path + [name]).join('/') => messages)
21
- end
22
-
23
- if object.model
24
- object.model.errors.messages.each do |name, messages|
19
+ if object.respond_to? :errors
20
+ object.errors.messages.each do |name, messages|
25
21
  error_messages.merge!((path + [name]).join('/') => messages)
26
22
  end
27
23
  end
28
24
 
29
- object.model&.attributes&.each do |attribute_key, attribute_value|
30
- if attribute_value.is_a?(Array)
31
- attribute_value.each_with_index do |array_attribute_value, array_attribute_key|
32
- error_messages.merge!(
33
- error_messages(
34
- array_attribute_value,
35
- path + [attribute_key] + [array_attribute_key]
25
+ if object.respond_to? :model
26
+ if object.model
27
+ object.model.errors.messages.each do |name, messages|
28
+ error_messages.merge!((path + [name]).join('/') => messages)
29
+ end
30
+ end
31
+
32
+ object.model&.attributes&.each do |attribute_key, attribute_value|
33
+ if attribute_value.is_a?(Array)
34
+ attribute_value.each_with_index do |array_attribute_value, array_attribute_key|
35
+ error_messages.merge!(
36
+ error_messages(
37
+ array_attribute_value,
38
+ path + [attribute_key] + [array_attribute_key]
39
+ )
36
40
  )
37
- )
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.8.6.1'
5
+ VERSION = '1.8.6.6'
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.1
4
+ version: 1.8.6.6
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-26 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers