Sha256: c09828bf416ef8c7b4dc03c9b5eabbdd6ea26b9b6d453c1af969eaf737d50b90
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
module Blacklight::User # This gives us an is_blacklight_user method that can be included in # the containing applications models. # SEE ALSO: The /lib/blacklight/engine.rb class for how when this # is injected into the hosting application through ActiveRecord::Base extend def self.included(base) base.send :has_many, :bookmarks, :dependent => :destroy, :as => :user base.send :has_many, :searches, :dependent => :destroy, :as => :user base.send :include, InstanceMethods end # The following methods will be included in any active model object # that calls "is_blacklight_user" module InstanceMethods # fixme: This needs to be re-implemented def last_search_url return self.searches.last end def has_bookmarks? bookmarks.count > 0 end def has_searches? searches.count > 0 end def bookmarked_document_ids self.bookmarks.map{|bm|bm.document_id} end # see #current_bookmark_for, is easier def document_is_bookmarked?(document_id) bookmarked_document_ids.include? document_id end # returns a Bookmark object if there is one for document_id, else # nil. def existing_bookmark_for(document_id) # to_a, we don't want to go to the database, we want to use cached # copy. self.bookmarks.to_a.find {|b| b.document_id == document_id} end def documents_to_bookmark=(docs) docs.each do |doc| self.bookmarks.create(doc) unless bookmarked_document_ids.include?(doc[:document_id]) end end end # /InstanceMethods end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blacklight-3.0pre2 | lib/blacklight/user.rb |
blacklight-3.0pre1 | lib/blacklight/user.rb |