Sha256: 6861a721142d1ebef9c5705b8c7287a8812305edc1e09c84ec9a61bfcdc30fdd

Contents?: true

Size: 1.07 KB

Versions: 56

Compression:

Stored size: 1.07 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
      # Find all records matching all of the given tags.
      # Separate multiple tags by comma.
      def tagged_with(names)
        if names.is_a? String
          names = names.split(/,\s*/)
        end
        super(names: names, match: :all)
      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

56 entries across 56 versions & 1 rubygems

Version Path
alchemy_cms-5.3.8 lib/alchemy/taggable.rb
alchemy_cms-5.3.7 lib/alchemy/taggable.rb
alchemy_cms-5.3.6 lib/alchemy/taggable.rb
alchemy_cms-5.3.5 lib/alchemy/taggable.rb
alchemy_cms-5.3.4 lib/alchemy/taggable.rb
alchemy_cms-5.3.3 lib/alchemy/taggable.rb
alchemy_cms-5.3.2 lib/alchemy/taggable.rb
alchemy_cms-5.3.1 lib/alchemy/taggable.rb
alchemy_cms-5.3.0 lib/alchemy/taggable.rb
alchemy_cms-5.2.7 lib/alchemy/taggable.rb
alchemy_cms-5.2.6 lib/alchemy/taggable.rb
alchemy_cms-5.1.10 lib/alchemy/taggable.rb
alchemy_cms-5.0.10 lib/alchemy/taggable.rb
alchemy_cms-5.2.5 lib/alchemy/taggable.rb
alchemy_cms-5.1.9 lib/alchemy/taggable.rb
alchemy_cms-5.0.9 lib/alchemy/taggable.rb
alchemy_cms-5.2.4 lib/alchemy/taggable.rb
alchemy_cms-5.1.8 lib/alchemy/taggable.rb
alchemy_cms-5.0.8 lib/alchemy/taggable.rb
alchemy_cms-5.0.7 lib/alchemy/taggable.rb