better_params 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/lib/better_params/params_destroy_info.rb +9 -1
- data/lib/better_params/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: fc59027f4b9a9d99bd768339cf3368aac2536c08a393d22d46b1b379a1a6a306
|
4
|
+
data.tar.gz: 2a77e2116e608a834e0990bc1eda84a339f080f65f20c0b6da124792ed0c7497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ae84302b1b87b675b912702078df485e007b8ff24877c67e8cb477b7828f454cf1126a5bd41a2a21c05757676c97978920aac2b0838a96e4ba941ebc31feae
|
7
|
+
data.tar.gz: 4cc0c0594260ab44f3af13f737c42fe51b59c9f7e148e2aec27808336b1b441ab4dc2a378d2599743d9c056611fcbce238c81f366a5c9c5718d5fb5df6b7cd30
|
@@ -16,8 +16,10 @@ module BetterParams
|
|
16
16
|
nested_params = params[key]
|
17
17
|
next params if nested_params.nil?
|
18
18
|
|
19
|
+
# Try to fetch relation value
|
20
|
+
relation = object.public_send(relation_key(key))
|
21
|
+
|
19
22
|
# Can't process key if a nested object doesn't exists
|
20
|
-
relation = object.public_send(key)
|
21
23
|
next params if relation.nil?
|
22
24
|
|
23
25
|
if relation.is_a? Enumerable
|
@@ -49,6 +51,12 @@ module BetterParams
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
54
|
+
# Removes the "_attributes" suffix if exists
|
55
|
+
def relation_key(key)
|
56
|
+
match_data = key.to_s.match(/(.+)_attributes\z/)
|
57
|
+
match_data.nil? ? key : match_data[1].to_sym
|
58
|
+
end
|
59
|
+
|
52
60
|
# Adds { id: 1, _destroy: true } objects to an array if an object with id
|
53
61
|
# is not exists in the array but exists in a relation
|
54
62
|
def add_destroy_info(params_array, relation)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bazov Peter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|