Sha256: d704b5ee33e914b68dc4e3669e8111422aba1ec6afd2f480c935f86633b96d6d

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

module Tagalong
  module Taggable
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def tagalong_taggable
        class_eval do
          has_many :tagalong_taggings, :class_name => 'Tagalong::TagalongTagging', :as => :taggable
          has_many :tagalong_tags, :class_name => 'Tagalong::TagalongTag', :through => :tagalong_taggings
          include Tagalong::Taggable::InstanceMethods
        end
      end
    end

    module InstanceMethods
      def has_tag?(name)
        return self.tagalong_tags.map { |r| r.name }.include?(name)
      end

      def tags
        return self.tagalong_tags.order("number_of_references DESC").map { |r| r.name }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tagalong-0.0.3 lib/tagalong/taggable.rb
tagalong-0.0.1 lib/tagalong/taggable.rb