Sha256: 365e100caaf2bf71e4558e5c2001b094af064847908497553df5441d6c004d14

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

module Iconly
  module Concerns
    module Models
      module Project
        extend ActiveSupport::Concern

        included do
          belongs_to :user, class_name: 'User'
          has_many :project_icons
          has_many :icons, through: :project_icons

          extend FriendlyId
          friendly_id :name, use: [:slugged, :scoped], scope: :user

          scope :owned_by, ->(owner_id) { where('iconly_projects.user_id' => owner_id) }
          scope :without_icons, -> { where.not(id: ProjectIcon.select(:project_id)) }
        end

        private

        def should_generate_new_friendly_id?
          name_changed?
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iconly-1.0.0 lib/iconly/concerns/models/project.rb