Sha256: 6f27d0a49c89f574f775066cb5d42a2c89c95159f96dd454bb0475ef4775a7b9

Contents?: true

Size: 1.04 KB

Versions: 30

Compression:

Stored size: 1.04 KB

Contents

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

30 entries across 30 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 lib/alchemy/taggable.rb
alchemy_cms-4.6.6 lib/alchemy/taggable.rb
alchemy_cms-4.6.5 lib/alchemy/taggable.rb
alchemy_cms-4.5.1 lib/alchemy/taggable.rb
alchemy_cms-4.4.5 lib/alchemy/taggable.rb
alchemy_cms-4.6.4 lib/alchemy/taggable.rb
alchemy_cms-4.6.3 lib/alchemy/taggable.rb
alchemy_cms-4.6.2 lib/alchemy/taggable.rb
alchemy_cms-4.6.1 lib/alchemy/taggable.rb
alchemy_cms-4.6.0 lib/alchemy/taggable.rb
alchemy_cms-4.5.0 lib/alchemy/taggable.rb
alchemy_cms-4.4.4 lib/alchemy/taggable.rb
alchemy_cms-4.4.3 lib/alchemy/taggable.rb
alchemy_cms-4.4.2 lib/alchemy/taggable.rb
alchemy_cms-4.4.1 lib/alchemy/taggable.rb
alchemy_cms-4.4.0 lib/alchemy/taggable.rb
alchemy_cms-4.3.2 lib/alchemy/taggable.rb
alchemy_cms-4.2.4 lib/alchemy/taggable.rb
alchemy_cms-4.3.1 lib/alchemy/taggable.rb
alchemy_cms-4.2.3 lib/alchemy/taggable.rb