lib/likeable/module_methods.rb in likeable-0.1.1 vs lib/likeable/module_methods.rb in likeable-0.1.2

- old
+ new

@@ -6,10 +6,12 @@ ### Module Methods ### # ------------------ # class << self + attr_writer :cast_id, :find_one, :find_many + def classes (@classes||[]).flatten end def classes=(*args) @@ -62,26 +64,38 @@ @after_like = block if block.present? @after_like ||= lambda {|like|} @after_like end - def find_many=(find_many) - @find_many = find_many + def after_unlike(&block) + @after_unlike = block if block.present? + @after_unlike ||= lambda {|like|} + @after_unlike end + def adapter=(adapter) + self.find_one = adapter.find_one + self.find_many = adapter.find_many + @adapter = adapter + end + + def cast_id(id) + @cast_id ||= if @adapter && @adapter.respond_to?(:cast_id) + @adapter.cast_id + else + DefaultAdapter.cast_id + end + @cast_id.call(id) + end + def find_many(klass, ids) - @find_many ||= lambda {|klass, ids| klass.where(:id => ids)} + @find_many ||= DefaultAdapter.find_many @find_many.call(klass, ids) end - def find_one(klass, id) - @find_one ||= lambda {|klass, id| klass.where(:id => id).first} + @find_one ||= DefaultAdapter.find_one @find_one.call(klass, id) - end - - def find_one=(find_one) - @find_one = find_one end def user_class begin @user_class ||= ::User