dcidev_active_record 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dcidev_active_record.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f162b561542bc46075a729b74e1a12a030a60f30b427d89d65d7edf2020e7e6
|
4
|
+
data.tar.gz: 7a48a57c3d0f6fb8c78cf6ef8a035d9159c4555b30451cf9e93d1987f63651a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8a8c0aa82a3d1dd37e35bd67920c052f0e223caf02842792231921cb5091889fda528214fb52beeb7469ce3ac42960811bc540f95f5dc76572540031a750db
|
7
|
+
data.tar.gz: 2f1be735bd55d21fc8563d59e17782913065383fa8bea9fb60231153348dc5ea783d65a10908cef2c9c3c1986c5dbe8d7ad270d425f4db588c52de09b6f398c9
|
data/lib/dcidev_active_record.rb
CHANGED
@@ -22,6 +22,20 @@ module DcidevActiveRecord
|
|
22
22
|
scope :mysql_json_contains, ->(column, key, value) {"JSON_EXTRACT(#{column}, '$.\"#{key}\"') LIKE \"%#{value}%\""}
|
23
23
|
end
|
24
24
|
|
25
|
+
def replace_child_from_array(new_child = [], column_name: "", child_name: "")
|
26
|
+
new_child = new_child.to_a
|
27
|
+
formatted = []
|
28
|
+
existing_child = eval("self.#{child_name}")
|
29
|
+
existing_child_values = existing_child.pluck(column_name.to_sym)
|
30
|
+
delete_child = existing_child_values - new_child
|
31
|
+
(existing_child_values + new_child).uniq.each do |lc|
|
32
|
+
attr = { column_name => lc, "_destroy" => delete_child.include?(lc) }
|
33
|
+
id = existing_child.detect { |ec| eval("ec.#{column_name} == #{lc.is_a?(String) ? "'#{lc}'" : lc}") }
|
34
|
+
attr["id"] = id.id if id.present?
|
35
|
+
formatted << attr
|
36
|
+
end
|
37
|
+
formatted
|
38
|
+
end
|
25
39
|
|
26
40
|
def update_by_params(params, set_nil = true)
|
27
41
|
ActiveRecord::Base.transaction do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcidev_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Punto Damar P
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Testing phase
|
14
14
|
email:
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
40
|
+
rubygems_version: 3.2.3
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: This gem extends ActiveRecord features
|