Sha256: e1866d11155cfd1daa8dbe8351c655a4636f1f2949e3de975f3f670c575f0e20

Contents?: true

Size: 1.39 KB

Versions: 16

Compression:

Stored size: 1.39 KB

Contents

module RailsAdminImageManager
  class Tag < ApplicationRecord

    # == Extensions ===========================================================

    # == Constants ============================================================

    # == Attributes ===========================================================

    # == Callbacks ============================================================

    # == Relationships ========================================================

    has_and_belongs_to_many :files, class_name: 'RailsAdminImageManager::File', join_table: 'image_manager_files_tags', foreign_key: :image_manager_tag_id, association_foreign_key: :image_manager_file_id

    # == Validations ==========================================================

    validates_presence_of :name

    validates_uniqueness_of :name

    # == Scopes ===============================================================

    scope :with_files, -> { joins(:files).distinct }

    # == Instance Methods =====================================================

    # == Class Methods ========================================================

    self.table_name = 'image_manager_tags'

    def self.retrieve_or_create_tag(tag_string)
      tag = RailsAdminImageManager::Tag.find_by({name: tag_string})
      if tag.present?
        return tag
      else
        return RailsAdminImageManager::Tag.new({name: tag_string})
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rails_admin_image_manager-0.1.34 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.33 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.31 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.30 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.3 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.29 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.28 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.27 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.26 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.25 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.24 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.23 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.22 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.21 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.20 app/models/rails_admin_image_manager/tag.rb
rails_admin_image_manager-0.1.15 app/models/rails_admin_image_manager/tag.rb