Sha256: 18ac184621b8fc6f78e0c72c46308d42742c42b50ead17a1a9bdba8342565852

Contents?: true

Size: 740 Bytes

Versions: 1

Compression:

Stored size: 740 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, :dependent => :destroy
          has_many :tagalong_tags, :class_name => 'Tagalong::TagalongTag', :through => :tagalong_taggings
          include Tagalong::Taggable::InstanceMethods
        end
      end
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tagalong-0.1.4 lib/tagalong/taggable.rb