bullet_train-fields 1.6.2 → 1.6.4

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: 1e943348cf70848446d008b48ff4da9122f347666fbc80ade2dd318f612fb318
4
- data.tar.gz: 518037194a7038a6164b445735d4fd5c2aa9c96820439b450944d18e89ca1036
3
+ metadata.gz: e05d81fd71bb84dcc8453ed6ab245da56f66c8a7d21c3a623494853fe08f9167
4
+ data.tar.gz: 8b22fb9961197d36a6e9847a181772dbe6a783dd5e9c085afcf4ee3d8c02468d
5
5
  SHA512:
6
- metadata.gz: 50750c79e54b4581a25cc0feb810f32f2d924c35b505d3cfc758e9f54e13058d743da9d654f36f9fba57f1840de1e9f3b48c5173a9d2f72bfc33da60ac366ef2
7
- data.tar.gz: 1362ef20224a1d9cd9d9b80e75b9d0f2254b3bd685a39cd2ed1cca188f3a90e152bc3b3f7efadb29d9d4f6fd49a574586ff7ad0c8989ae945d2122607e7ef615
6
+ metadata.gz: 9f166d7e06da69090b3e98d85e30f0646e8fa2104ff427ac40f6856a287541ee4bfe37227d2bfc110b15d06ac31473eda5e8cb92be9522b52fa4ee034d4d777a
7
+ data.tar.gz: 5f0f06bc222c60820166839137009c69e66e1937a2a43b899054bbb92709225c3eea372d6d09fa82babf7e857aea64faa39d843e37ea1a5c7fe4536a99f1412b
@@ -11,6 +11,10 @@ module Fields::SuperSelectSupport
11
11
  end
12
12
 
13
13
  def create_model_if_new(id)
14
+ ActiveSupport::Deprecation.warn(
15
+ "#create_model_if_new is deprecated. " \
16
+ "Use #ensure_backing_models_on instead. See examples at https://bullettrain.co/docs/field-partials/super-select#accepting-new-entries"
17
+ )
14
18
  if id.present?
15
19
  unless /^\d+$/.match?(id)
16
20
  id = yield(id).id.to_s
@@ -20,10 +24,24 @@ module Fields::SuperSelectSupport
20
24
  end
21
25
 
22
26
  def create_models_if_new(ids)
27
+ ActiveSupport::Deprecation.warn(
28
+ "#create_models_if_new is deprecated. " \
29
+ "Use #ensure_backing_models_on instead. See examples at https://bullettrain.co/docs/field-partials/super-select#accepting-new-entries"
30
+ )
23
31
  ids.map do |id|
24
32
  create_model_if_new(id) do
25
33
  yield(id)
26
34
  end
27
35
  end
28
36
  end
37
+
38
+ # See examples at https://bullettrain.co/docs/field-partials/super-select#accepting-new-entries
39
+ def ensure_backing_models_on(collection, id: nil, ids: [id])
40
+ ids = ids.compact_blank
41
+ return ids if ids.empty?
42
+
43
+ existing_ids = collection.where(id: ids).ids.map(&:to_s)
44
+ new_ids = ids.without(existing_ids).filter_map { yield(collection, _1)&.id&.to_s }
45
+ (existing_ids + new_ids).then { id ? _1.first : _1 }
46
+ end
29
47
  end
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Fields
3
- VERSION = "1.6.2"
3
+ VERSION = "1.6.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-10 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard