pretty-api 0.3.0 → 0.4.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +18 -1
- data/lib/pretty_api/active_record/associations.rb +1 -1
- data/lib/pretty_api/parameters/nested_attributes.rb +6 -1
- data/lib/pretty_api/version.rb +1 -1
- 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: 9668f43a29b655b7f053e2e225d8d5fd6cc7e40cf51f07d52604d9032056ccf3
|
4
|
+
data.tar.gz: 587fce31fb41a7c225dea094650750cf91f197f94f32c45d912e8bd730cfb825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ee8e896e7bb56156361b8e2f3ccfc1fb85409ffd37b447fcf325ebc80216f80dcaf75f5aede2c4eec4c739e924d034e07aa63833126ea5e938763b1d57b5dbe
|
7
|
+
data.tar.gz: eb77378853a03d88cfa769bde7be327cbc4bc7acd326f32b32ce06b01d0c025f09ae454aa934e9b59d2e29a823bcf3fb1598c16fded819c27633a8069e929b4e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2024-06-04
|
4
|
+
|
5
|
+
- Add support for www-form-urlencoded / multipart format: Fix "No implicit conversion of String into Integer"
|
6
|
+
|
7
|
+
## [0.3.1] - 2024-06-01
|
8
|
+
|
9
|
+
- Fix possible "Unitialized Constant" error when inferring association classes that are namespaced
|
10
|
+
|
3
11
|
## [0.3.0] - 2024-06-01
|
4
12
|
|
5
13
|
- Support for ActionController::Parameters from Rails
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Exemple with an organization that has 2 services. Let's say we would like to upd
|
|
30
30
|
|
31
31
|
### With PrettyAPI
|
32
32
|
|
33
|
-
You can omit `_attributes` from your attributes and you can omit everything that you would like to destroy as well.
|
33
|
+
You can omit `_attributes` from your attributes and you can omit `everything that you would like to destroy` as well.
|
34
34
|
|
35
35
|
```json
|
36
36
|
{
|
@@ -60,6 +60,23 @@ More exemples
|
|
60
60
|
}
|
61
61
|
```
|
62
62
|
|
63
|
+
Support baked for www-form-urlencoded / multipart format. Services will be converted internally to an array discarding
|
64
|
+
all superfluous indexes.
|
65
|
+
|
66
|
+
```json
|
67
|
+
{
|
68
|
+
"organization": {
|
69
|
+
"id": 1,
|
70
|
+
"services": {
|
71
|
+
"0": {
|
72
|
+
"id": 2,
|
73
|
+
"name": "Service to update"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|
63
80
|
## How it works
|
64
81
|
|
65
82
|
Because Rails is a framework built on conventions over configurations, it is possible to use reflections on your
|
@@ -6,7 +6,7 @@ module PrettyApi
|
|
6
6
|
result[model] ||= {}
|
7
7
|
|
8
8
|
association = attribute_association(model, association_name)
|
9
|
-
association_class = association.
|
9
|
+
association_class = association.klass
|
10
10
|
|
11
11
|
result[model][association_name] = {
|
12
12
|
model: association_class,
|
@@ -37,9 +37,14 @@ module PrettyApi
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def parse_has_many_association(record, params, assoc_key, assoc_info)
|
40
|
+
# www-form-urlencoded / multipart-form-data
|
41
|
+
params[assoc_key] = params[assoc_key].values if params[assoc_key].is_a?(Hash)
|
42
|
+
|
40
43
|
(params[assoc_key] || []).each do |p|
|
41
44
|
assoc_primary_key = record.try(:class).try(:primary_key)
|
42
|
-
assoc = record.try(assoc_key).try(:detect)
|
45
|
+
assoc = record.try(assoc_key).try(:detect) do |r|
|
46
|
+
r.try(assoc_primary_key) == p[assoc_primary_key]
|
47
|
+
end
|
43
48
|
parse_nested_attributes(assoc, p, nested_tree[assoc_info[:model]])
|
44
49
|
end
|
45
50
|
end
|
data/lib/pretty_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James St-Pierre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|