# FacadeパターンはControllerとViewからプレゼンテーションロジックを抽出したPlain Ruby Objectのインターフェイス # 参考↓ # https://refactoring.guru/ja/design-patterns/facade/ruby/example # https://blog.appsignal.com/2020/03/18/facade-pattern-in-rails-for-performance-and-maintainability.html ## Facade未使用 class BooksController < ApplicationController def index @books = if params[:query].present? current_user.books.where('name ILIKE ?', "%#{params[:query]}%") elsif params[:isbn].present? current_user.books.where(isbn: params[:isbn]) else current_user.books end @books.order(created_at: :desc).page(params[:page]) @recommended = @books.where(some_complex_query: true) end end ## Facade使用 class BooksController < ApplicationController def index @index_facade = Books::IndexFacade.new(user: current_user, params: params) end end