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.22 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.21 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.20 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.19 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.18 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.17 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.16 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.15 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.14 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.13 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.12 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.11 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.10 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.9 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.8 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.7 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.6 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.5 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.4 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb
keppler-2.1.3 installer/core/rockets/keppler_capsules/app/models/keppler_capsules/capsule_association.rb