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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ae1f5a395773d7742e4e8d35c5bd8ab123c474b5e0bef974b3f493b3149e97f
4
- data.tar.gz: c501cd773a268868814c2c8ebe08dd425eea7be219c2f3d72e52cb292305aa0e
3
+ metadata.gz: 9668f43a29b655b7f053e2e225d8d5fd6cc7e40cf51f07d52604d9032056ccf3
4
+ data.tar.gz: 587fce31fb41a7c225dea094650750cf91f197f94f32c45d912e8bd730cfb825
5
5
  SHA512:
6
- metadata.gz: f6826d7e3534689df805027042f6e65282a29fcb08456c8384f5598b9c7727613de31e55d7daa92509e874ce2dd3dc2bb11c7f0b734bcfa3d3ffb1e197ad3e99
7
- data.tar.gz: bf162d88d8828702df78a4e731f0dd4c64bdc1bebdd94cd61cece7f2a0047a622111de4460b513343cb5d38f3459643d12e8bd9918ab0f24e85611082caf2bf9
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.class_name.constantize
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) { |r| r.try(assoc_primary_key) == p[assoc_primary_key] }
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
@@ -1,3 +1,3 @@
1
1
  module PrettyApi
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
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.3.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-01 00:00:00.000000000 Z
11
+ date: 2024-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails