tramway-api 1.8.6.1 → 1.8.6.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c073884812f246c0b76d5367b19c2f1348dbe8539286b08027487e716e2dd959
|
4
|
+
data.tar.gz: d49ede45c33a877a8deea8dcb9fb0285d1ef0d2154cd9e44109b0801e0280e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
20
|
-
|
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
|
30
|
-
if
|
31
|
-
|
32
|
-
error_messages.merge!(
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
data/lib/tramway/api/version.rb
CHANGED
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.
|
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-
|
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
|