tramway-api 1.8.6 → 1.8.6.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a073d2cac39ca7ee025468a271a4a85ba900c81693d62556ac76f1c7962882e2
|
4
|
+
data.tar.gz: 34fadb2c4df760f32bc76d14a2c25fa2c1e9819c3c6a738a82e0ba05d7535b1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a5f6ce365af846d668d355b7858e1ae31f3c8c4dd9afabaa8f9348cfb786c0fd470300bf904e1c381e14cd9499e286154cabd62401fee14e8c896062b6443ea
|
7
|
+
data.tar.gz: c8ab7d0c75fb7d51ea2c9b2d9173120114387eaed83541f3e0ca9d41c12c874c311e492163769410a06c980648633ed1dbfa55b5a1a412be209b62ab980d6fbb
|
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
|
@@ -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.
|
9
|
+
id_method = Tramway::Api.default_id_method_of(model: object.class) || :uuid
|
10
10
|
object.send(id_method)
|
11
11
|
end
|
12
12
|
|
@@ -16,8 +16,10 @@ 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
|
-
|
19
|
+
if object.respond_to? :errors
|
20
|
+
object.errors.messages.each do |name, messages|
|
21
|
+
error_messages.merge!((path + [name]).join('/') => messages)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
if object.model
|
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.5
|
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
|