pretty-api 0.3.1 → 0.4.1

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: 4bd1b6f06b9359270546fda79b7afea4e34789ebda0c9710dcd9e29843918e12
4
- data.tar.gz: 2245430d8a8742e742108239ba035f65bd63a79f21c99b355d3edfdd30492e4d
3
+ metadata.gz: 3133e955e326cec2857e0c68eb8013c18f370a0ad92d94793e973950690cd143
4
+ data.tar.gz: 3052057563fbbf602cdebcedc398a09b1b9fb31e68678c1f97e055084c78d2ad
5
5
  SHA512:
6
- metadata.gz: 354f2859bdffce8317f9dc1d14a539a5600e070dfc9f529b174e66c46cff88d3b5a5c84261a9b122bf905da71b3500dc4c3ec0bb46dc610b5831e80aa0a916b5
7
- data.tar.gz: 4a145833591f955c72c4a66e5492c186dc11381c936a2060a7004b05cf6bbaa6d102f76386b1e593ec95908fee6554ed3d88aa79d051a3f499160017dfd566c6
6
+ metadata.gz: 5eeb04d0536d7757ebc0c4d95bd5e6fe937d39fc6aadbd6637feee8c0b0e154ae6a0d8b3009f6f410fbc763ec4dae2535551724b3ec33047a015907540c900d7
7
+ data.tar.gz: ba54bd9943b27a2731518a1f6ec1201b645b8331c5eb099f2dcc6ba467561a2116d2c3c011eb2848ea9888be13e264faf113c2954f5b32478c890961baa2d832
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2024-06-04
4
+
5
+ - Fix `undefined method `each' for nil` when PrettyAPI is used on record that doesn't have associations
6
+
7
+ ## [0.4.0] - 2024-06-04
8
+
9
+ - Add support for www-form-urlencoded / multipart format: Fix "No implicit conversion of String into Integer"
10
+
3
11
  ## [0.3.1] - 2024-06-01
4
12
 
5
13
  - Fix possible "Unitialized Constant" error when inferring association classes that are namespaced
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,6 +6,8 @@ module PrettyApi
6
6
  end
7
7
 
8
8
  def parse(record, params)
9
+ return params if nested_tree[record.class].blank?
10
+
9
11
  parse_nested_attributes(record, params, nested_tree[record.class])
10
12
  end
11
13
 
@@ -37,6 +39,9 @@ module PrettyApi
37
39
  end
38
40
 
39
41
  def parse_has_many_association(record, params, assoc_key, assoc_info)
42
+ # www-form-urlencoded / multipart-form-data
43
+ params[assoc_key] = params[assoc_key].values if params[assoc_key].is_a?(Hash)
44
+
40
45
  (params[assoc_key] || []).each do |p|
41
46
  assoc_primary_key = record.try(:class).try(:primary_key)
42
47
  assoc = record.try(assoc_key).try(:detect) { |r| r.try(assoc_primary_key) == p[assoc_primary_key] }
@@ -1,3 +1,3 @@
1
1
  module PrettyApi
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.4.1".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.1
4
+ version: 0.4.1
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.5.9
73
+ rubygems_version: 3.5.11
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Pretty API for Rails