README.md in findit-0.1.0 vs README.md in findit-1.0.0

- old
+ new

@@ -1,10 +1,10 @@ # Findit -Tired of writing fat controllers? But you must do all these queries.. There is a solution, move it to a Finder class. +Tired of writing fat controllers? But you must do all these queries.. There is a solution, move it to a special Finder class! -Don't write this: +Stop writing this: ```ruby class SomeController def index @cache_key = ( @@ -45,11 +45,13 @@ def initialize(params) # some initialize, maybe params parse end - def call + private + + def find # put here you find logic end end ``` @@ -89,17 +91,19 @@ ## Per module documentation ### Collections -It makes Finder work as Enumerator. -Result can be accessed with `each`, `[]` and `size` methods, but to make things work you *must* implement `call` method. +It makes Finder work as Enumerator with lazy load. +Result can be accessed with `each`, `[]` and `size` methods, but to make things work you *must* implement `find` method. ``` class PostFinder incliude Findit::Collections - def call + private # make it private, so no one call it without lazy load + + def find Post.where(user_id: 1) end end @posts = PostFinder.new @@ -128,16 +132,17 @@ cache_key do [@user.id, @query] # here you put any stuff that result of finder depend on it end # custom initializer, do whatever you want here - def initialize(user, options = {}) - @user = user + def initialize(options = {}) + @user = options.fetch(:user) @query = options[:query] end + private # Here we fetch results. You MUST implement it - def call + def find scope = scope.where(user_id: @user.id) scope = scope.where('description like :query', query: @query) if @query.present? scope end end