Sha256: e69424c86b4d4fce129e60cd95e58f7257e35bf6e6c91f33f709a728e25a6769

Contents?: true

Size: 892 Bytes

Versions: 2

Compression:

Stored size: 892 Bytes

Contents

module EnjuBookmark
  module BookmarkManifestation
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def enju_bookmark_manifestation_model
        include InstanceMethods
        has_many :bookmarks, :include => :tags, :dependent => :destroy, :foreign_key => :manifestation_id
        has_many :users, :through => :bookmarks

        searchable do
          string :tag, :multiple => true do
            bookmarks.map{|bookmark| bookmark.tag_list}.flatten
          end
          text :tag do
            bookmarks.map{|bookmark| bookmark.tag_list}.flatten
          end
        end
      end
    end

    module InstanceMethods
      def bookmarked?(user)
        return true if user.bookmarks.where(:url => url).first
        false
      end

      def tags
        bookmarks.map{|bookmark| bookmark.tags}.flatten
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
enju_bookmark-0.1.2.pre17 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre16 lib/enju_bookmark/manifestation.rb