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? }
|
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
|
||||||
|
|
Reference in a new issue