1
0
Fork 0

Add method OrgUnit#requires_resource?

This commit is contained in:
Alex Kotov 2019-10-21 12:25:52 +05:00
parent 64184da896
commit c9bf4f2a85
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -40,13 +40,8 @@ class OrgUnit < ApplicationRecord
absence: { unless: :requires_parent? } absence: { unless: :requires_parent? }
validates :resource, validates :resource,
presence: { presence: { if: :requires_resource?, message: :required },
if: ->(record) { record.kind&.resource_type }, absence: { unless: :requires_resource? }
message: :required,
},
absence: {
unless: ->(record) { record.kind&.resource_type },
}
validate :parent_matches_kind validate :parent_matches_kind
@ -64,6 +59,10 @@ class OrgUnit < ApplicationRecord
kind&.parent_kind kind&.parent_kind
end end
def requires_resource?
kind&.resource_type
end
private private
def parent_matches_kind def parent_matches_kind