Sha256: 2c027a67f83c9f8c86f3bd89c9bacbcc42e3914a1907fe38e951e84ae47e42bb
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
# # Example usage: # # #/app/finders/posts_finders.rb # class PostFinder # include Findit::Collections # # cache_key do # [@user.id, @query] # end # # cache_tags do # {user_id: @user.id} # end # # expire_in 30.minutes # # def initialize(user, options = {}) # @user = user # @query = options[:query] # end # # def call # scope = scope.where(user_id: @user.id) # scope = scope.where('description like :query', query: @query) if @query.present? # scope # end # end # # #/app/controllers/posts_controller.rb # class PostsController < ApplicationController # def index # @posts = PostFinder.new(user: current_user) # end # end # # #/app/views/posts/index.html.erb # <% cache(@posts, tags: @posts.cache_tags, expire_in: @posts.expire_in) do %> # <%= render 'post' colection: @posts, as: :post%> # module Findit module Collections include Enumerable extend ActiveSupport::Concern included do delegate :each, :[], :size, :empty?, to: :data end module ClassMethods def cache_key(&block) define_method :cache_key do @cache_key ||= ActiveSupport::Cache.expand_cache_key(instance_exec(&block)) end end end def call end undef :call def data return @data if defined?(@data) @data = call end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
findit-0.1.0 | lib/findit/collections.rb |