Sha256: 8469dfd20d3afff623703aa53782d57b36dd1172f53e1dd3e6f58210fe9d869c

Contents?: true

Size: 880 Bytes

Versions: 7

Compression:

Stored size: 880 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
            tags.collect(&:name)
          end
          text :tag do
            tags.collect(&:name)
          end
        end
      end
    end

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

      def tags
        if self.bookmarks.first
          self.bookmarks.tag_counts
        else
          []
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
enju_bookmark-0.1.2.pre15 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre14 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre13 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre12 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre11 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre10 lib/enju_bookmark/manifestation.rb
enju_bookmark-0.1.2.pre9 lib/enju_bookmark/manifestation.rb