Sha256: 7ef1bffc4a6fa0b191c3db0df717c76bd37e3e1e61a99b3ef6a8b1405cab8307
Contents?: true
Size: 636 Bytes
Versions: 15
Compression:
Stored size: 636 Bytes
Contents
module WithUsages extend ActiveSupport::Concern included do has_many :usages, as: :item before_destroy :ensure_unused! organic_on :usages end def usage_in_organization(organization = Organization.current) usages_in_organization(organization).first.try(:parent_item) end def usage_in_organization_of_type(type, organization = Organization.current) item = usage_in_organization(organization) item.is_a?(type) ? item : nil end private def ensure_unused! if usages.present? errors.add :base, :in_use, organization: usages.first.organization.name throw :abort end end end
Version data entries
15 entries across 15 versions & 2 rubygems