bullet_train-fields 1.6.3 → 1.6.5

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: ca44d0df23fb031f046e44ee74f1e0542b7895ff6e9f552e4a75edd0d2ef868a
4
+ data.tar.gz: cb75d3cac2fb1c0dca8422afcfd76143c6fa4bfc7ae058faa2999dc1aa25cc3f
5
5
  SHA512:
6
- metadata.gz: 55caaa8908c86ac0ba8244a6a5cd3fa0c22458ad800eb67919915b5c5b6c3b78bb878750f95333a65662fb90c13b19895fc4a0b6a90df72a4243e1ab19d8f9d8
7
- data.tar.gz: 1bfe6495284c9d399a4a079d57e3aa80bcdf3f0cd00fc9f333e570f0724420063217f33350f0d56cbef127caf4f5294c2ff474a7ebcfe71a5ee47f44882a15ab
6
+ metadata.gz: 3b2d08de8d17226dd7aa27e580555305e8e6cf7a3d6b53bc1f63b9861b6c3f8266873f882821e62234b3b2f3ee57c60871b9e655b871c74b8af1cd1bd0c2c65e
7
+ data.tar.gz: e1e3035151f57ec704e303fa32fe75757954e81d9132c2c852a53b2aa0096c1ccef921903fea5d0d4251a9c7483e116e829b5268b55b2277a6443563867bbd39
@@ -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.5"
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.5
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-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard