https://github.com/rubocop-hq/rubocop/tree/v0.28.0Assignment Branch Condition size for search is too high. [<10, 21, 5> 23.79/20] Assignment Branch Condition size for search is too high. [<10, 21, 5> 23.79/20]
GitHub - rubocop/rubocop at v0.28.0A Ruby static code analyzer and formatter, based on the community Ruby style guide. - GitHub - rubocop/rubocop at v0.28.0
Assignment Branch Condition size for search is too high. [<10, 21, 5> 23.79/20]
指摘を受けたソースコードは↓
def search
if params[:city_id]
pagy, offices = pagy Office.where(city_id: params[:city_id])
pagy_headers_merge(pagy)
elsif params[:keyword]
keywords = params[:keyword].split(/[[:blank:]]+/).select(&:present?)
pagy, offices = pagy_array([])
pagy_headers_merge(pagy)
keywords.each do |keyword|
offices += Office.where('name LIKE (?) OR
address LIKE (?) OR
near_station LIKE (?) OR
introduction LIKE (?) OR
company LIKE (?)',
"%#{keyword}%",
"%#{keyword}%",
"%#{keyword}%",
"%#{keyword}%",
"%#{keyword}%")
end
else
pagy, offices = pagy(Office.all)
pagy_headers_merge(pagy)
end
render json: offices, each_serializer: OfficeIndexSerializer, include: '**'
end