better_params 0.3.0 → 0.4.0

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: f9b478ac72c9be93b9adf5f85d63de10064d6a3482f943dc286e98e100460ba3
4
- data.tar.gz: 5d0265c6ad4e5274c3372ea6704da5ab2064804d6d971031ad50e00d24ca34f3
3
+ metadata.gz: fc59027f4b9a9d99bd768339cf3368aac2536c08a393d22d46b1b379a1a6a306
4
+ data.tar.gz: 2a77e2116e608a834e0990bc1eda84a339f080f65f20c0b6da124792ed0c7497
5
5
  SHA512:
6
- metadata.gz: 225c102e8196705747658a08be5a3e3e2d87825d0be9dd7c419c818ad8515d5777136a6a7787788bff310e34f0945206ff112ed9a684341f7d34a17c202fe90d
7
- data.tar.gz: 8da0c2c6b8111db083adb501475d4ba346d261e6c847ef0ef811fb235a872098b5e8cc286c39709881886cb0690de4b678fb0989e760a08c9e8f3f74c5fc5fbd
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)
@@ -1,3 +1,3 @@
1
1
  module BetterParams
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'.freeze
3
3
  end
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.3.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-10-19 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails