Add method OrgUnit#requires_resource?
This commit is contained in:
parent
64184da896
commit
c9bf4f2a85
1 changed files with 6 additions and 7 deletions
|
@ -40,13 +40,8 @@ class OrgUnit < ApplicationRecord
|
|||
absence: { unless: :requires_parent? }
|
||||
|
||||
validates :resource,
|
||||
presence: {
|
||||
if: ->(record) { record.kind&.resource_type },
|
||||
message: :required,
|
||||
},
|
||||
absence: {
|
||||
unless: ->(record) { record.kind&.resource_type },
|
||||
}
|
||||
presence: { if: :requires_resource?, message: :required },
|
||||
absence: { unless: :requires_resource? }
|
||||
|
||||
validate :parent_matches_kind
|
||||
|
||||
|
@ -64,6 +59,10 @@ class OrgUnit < ApplicationRecord
|
|||
kind&.parent_kind
|
||||
end
|
||||
|
||||
def requires_resource?
|
||||
kind&.resource_type
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parent_matches_kind
|
||||
|
|
Reference in a new issue