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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dcidev_active_record.rb +14 -0
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8241a63b734ee3eb8ca4198bb50a2d22243da122d516c8305d4a90c3172b2a13
4
- data.tar.gz: 3d3cabdb63b8bd0a52fc4eaf1813787a62cb91b027004ea74330e582299fa744
3
+ metadata.gz: 1f162b561542bc46075a729b74e1a12a030a60f30b427d89d65d7edf2020e7e6
4
+ data.tar.gz: 7a48a57c3d0f6fb8c78cf6ef8a035d9159c4555b30451cf9e93d1987f63651a9
5
5
  SHA512:
6
- metadata.gz: 679948d3dfe60825c43ce736e4ac7fe2a4e0bdd539bae0d44d68e58d25a19e0d7e57e7e210650b7bf051b68b7a0b1abb6883949fd965104168888014933715d1
7
- data.tar.gz: 4de885d42e3b81dba5cd97add3601335838a4fcb412049da2c33cc26529fa3a525b5a27050ce3ab2037b7edc070742065b143ef57c7e13e21885599f8917cbdc
6
+ metadata.gz: 0a8a8c0aa82a3d1dd37e35bd67920c052f0e223caf02842792231921cb5091889fda528214fb52beeb7469ce3ac42960811bc540f95f5dc76572540031a750db
7
+ data.tar.gz: 2f1be735bd55d21fc8563d59e17782913065383fa8bea9fb60231153348dc5ea783d65a10908cef2c9c3c1986c5dbe8d7ad270d425f4db588c52de09b6f398c9
@@ -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.7
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-05 00:00:00.000000000 Z
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.0.6
40
+ rubygems_version: 3.2.3
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: This gem extends ActiveRecord features