bullet_train-fields 1.6.3 → 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: 9d9a79757c0a951bf2b0e772ec5d7c442e94a9347f9694b7211b735b6612d10b
4
- data.tar.gz: b30a410c8c2fc05c420934f5e7245d02f04cb50f46b5d8c56d0036d37202f615
3
+ metadata.gz: e05d81fd71bb84dcc8453ed6ab245da56f66c8a7d21c3a623494853fe08f9167
4
+ data.tar.gz: 8b22fb9961197d36a6e9847a181772dbe6a783dd5e9c085afcf4ee3d8c02468d
5
5
  SHA512:
6
- metadata.gz: 55caaa8908c86ac0ba8244a6a5cd3fa0c22458ad800eb67919915b5c5b6c3b78bb878750f95333a65662fb90c13b19895fc4a0b6a90df72a4243e1ab19d8f9d8
7
- data.tar.gz: 1bfe6495284c9d399a4a079d57e3aa80bcdf3f0cd00fc9f333e570f0724420063217f33350f0d56cbef127caf4f5294c2ff474a7ebcfe71a5ee47f44882a15ab
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.3"
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.3
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-13 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