require 'redis' module Likeable mattr_accessor :facepile_default_limit self.facepile_default_limit = 9 ### Module Methods ### # ------------------ # class << self def classes (@classes||[]).flatten end def classes=(*args) @classes = args end # Likeable.model("Highlight") # ------------------------- # # turns a string into a model # "Highlight".constantize # => Highlight; "Hi1i6ht".constantize = #=> false def model(target_model) target_model.camelcase.constantize rescue NameError => ex return false end # Likeable.find_by_resource_id("highlight", 22) # ---------------------------------------- # # # ids)} @find_many.call(klass, ids) end def find_one(klass, id) @find_one ||= lambda {|klass, id| klass.where(:id => id).first} @find_one.call(klass, id) end def find_one=(find_one) @find_one = find_one end def user_class begin @user_class ||= ::User rescue NameError nil end end def user_class=(klass) raise ArgumentError, "Argument must be a class" unless klass.is_a?(Class) @user_class = klass end # Likeable.setup do |like| # like.redis = Redis.new(#...) # like.find_one = lambda {|klass, id | klass.where(:id => id)} # like.find_many = lambda {|klass, ids| klass.where(:id => ids)} # end def setup(&block) yield self unless block.blank? true end end end