Sha256: 99b8f8d07acfcb8ef60b8feb8fde129ae84b12fb03eff9be00f93aa980b53b67

Contents?: true

Size: 1.04 KB

Versions: 24

Compression:

Stored size: 1.04 KB

Contents

module KepplerCapsules
  class CapsuleAssociation < ApplicationRecord
    include KepplerCapsules::Concerns::StringActions
    include KepplerCapsules::Concerns::GeneratorActions
    include KepplerCapsules::Concerns::AssociationActions
    belongs_to :capsule
    validate :uniqueness_association

    def relationships
      [:belongs_to, :has_one, :has_many, :has_and_belongs_to_many]
    end

    def dependentions
      [[false, :nothing], [true, :destroy]]
    end

    def capsules_valids
      Capsule.all.select { |x| x unless x.name.eql?(self.capsule.name) }
    end

    def delete_association_line
      delete_association(self.capsule.name, self)
    end

    def association_exists?
      association = CapsuleAssociation.where(
        capsule_id: self.capsule,
        association_type: self.association_type,
        capsule_name: self.capsule_name)
      association.count == 0 ? false : true
    end

    private

    def uniqueness_association
      errors.add(:association_type, :uniqueness_association) if association_exists?
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
keppler-2.1.2 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.1 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.pre.p1 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb