effective_bootstrap 1.22.2 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/effective/form_input.rb +15 -0
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8525fb430647548ed163f61aacb3d1a5a582cbb6e5bf7182d2c69374cd4e5082
|
|
4
|
+
data.tar.gz: b5ba63ca4c4162696b289599106c8476ac3d1eceb557eff451b707ac4b9aa608
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9763f0b4a0e4a728d9601dcd9872fcd4ff921b7e6f55f31387a6a5be1c5fa2a0b6aac561c9b0d6203d83667455232804acb49342576cb1068e767d6c026ea598
|
|
7
|
+
data.tar.gz: 3dbec9987fc1bfaba4130ad9b4668cd5e1f462d0fd12ee5307d2a7dd4c2d45bf4ea4ee6faa9c21089fffb800428b52b526f6511b780ee3dff8ec4acb8050c9fc
|
|
@@ -226,6 +226,7 @@ module Effective
|
|
|
226
226
|
|
|
227
227
|
obj = (object.class == Class) ? object : object.class
|
|
228
228
|
return false unless obj.respond_to?(:validators_on)
|
|
229
|
+
return true if required_belongs_to?(obj, name)
|
|
229
230
|
|
|
230
231
|
if name.to_s.ends_with?('_id')
|
|
231
232
|
return required_presence?(obj, name) || required_presence?(obj, name[0...-3])
|
|
@@ -234,6 +235,20 @@ module Effective
|
|
|
234
235
|
required_presence?(obj, name)
|
|
235
236
|
end
|
|
236
237
|
|
|
238
|
+
def required_belongs_to?(obj, name)
|
|
239
|
+
return false unless obj.respond_to?(:reflect_on_all_associations)
|
|
240
|
+
|
|
241
|
+
reflection = obj.reflect_on_association(name.to_s.delete_suffix('_id'))
|
|
242
|
+
reflection ||= obj.reflect_on_all_associations(:belongs_to).find do |belongs_to|
|
|
243
|
+
Array(belongs_to.foreign_key).map(&:to_s).include?(name.to_s)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
return false unless reflection&.macro == :belongs_to
|
|
247
|
+
|
|
248
|
+
optional = reflection.options[:optional]
|
|
249
|
+
optional.nil? ? obj.belongs_to_required_by_default : !optional
|
|
250
|
+
end
|
|
251
|
+
|
|
237
252
|
def required_presence?(obj, name)
|
|
238
253
|
obj.validators_on(name).any? do |v|
|
|
239
254
|
(
|