Sha256: 9774ea3efe8c64eac843fe566e33a51b129ee4b5e6ce8f34602d5b98500479e4

Contents?: true

Size: 1.1 KB

Versions: 47

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Alchemy
  # ActsAsTaggableOn to Gutentag interface compatibility module
  # Include this module to add tagging support to your model.
  module Taggable
    def self.included(base)
      Gutentag::ActiveRecord.call base
      base.extend ClassMethods
      base.send(:alias_method, :tag_list, :tag_names)
    end

    # Set a list of tags
    # Pass a String with comma separated tag names or
    # an Array of tag names
    def tag_list=(tags)
      case tags
      when String
        self.tag_names = tags.split(/,\s*/)
      when Array
        self.tag_names = tags
      end
    end

    module ClassMethods
      def tagged_with(names = [], **args)
        if names.is_a? String
          names = names.split(/,\s*/)
        end

        unless args[:match]
          args[:match] = :all
        end

        if names.any?
          args[:names] = names
        end

        super(args)
      end

      # Returns all unique tags
      def tag_counts
        Gutentag::Tag.distinct.joins(:taggings)
          .where(gutentag_taggings: {taggable_type: name})
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 lib/alchemy/taggable.rb
alchemy_cms-7.3.3 lib/alchemy/taggable.rb
alchemy_cms-7.3.2 lib/alchemy/taggable.rb
alchemy_cms-7.2.7 lib/alchemy/taggable.rb
alchemy_cms-7.3.1 lib/alchemy/taggable.rb
alchemy_cms-7.3.0 lib/alchemy/taggable.rb
alchemy_cms-7.2.6 lib/alchemy/taggable.rb
alchemy_cms-7.2.5 lib/alchemy/taggable.rb
alchemy_cms-7.1.12 lib/alchemy/taggable.rb
alchemy_cms-7.0.15 lib/alchemy/taggable.rb
alchemy_cms-7.2.4 lib/alchemy/taggable.rb
alchemy_cms-7.1.11 lib/alchemy/taggable.rb
alchemy_cms-7.2.3 lib/alchemy/taggable.rb
alchemy_cms-7.1.10 lib/alchemy/taggable.rb
alchemy_cms-7.2.2 lib/alchemy/taggable.rb
alchemy_cms-7.1.9 lib/alchemy/taggable.rb
alchemy_cms-7.0.14 lib/alchemy/taggable.rb
alchemy_cms-7.2.1 lib/alchemy/taggable.rb
alchemy_cms-7.0.13 lib/alchemy/taggable.rb
alchemy_cms-7.1.8 lib/alchemy/taggable.rb