class Finder::Builder

Public Instance Methods

call(options, params) click to toggle source
# File lib/trailblazer/operation/finder.rb, line 26
def call(options, params)
  finder_class  = options[:"finder.class"]
  entity        = options[:"finder.entity"]
  action        = options[:"finder.action"]
  action        = :all unless %i[all single].include?(action)

  send("#{action}!", finder_class, entity, params, options[:"finder.action"])
end

Private Instance Methods

all!(finder_class, entity, params, *) click to toggle source
# File lib/trailblazer/operation/finder.rb, line 37
def all!(finder_class, entity, params, *)
  finder_class.new(entity: entity, params: params)
end
apply_id(params) click to toggle source
# File lib/trailblazer/operation/finder.rb, line 50
def apply_id(params)
  return if params[:id].nil?
  params[:id_eq] = params[:id]
end
single!(finder_class, entity, params, *) click to toggle source
# File lib/trailblazer/operation/finder.rb, line 41
def single!(finder_class, entity, params, *)
  apply_id(params)
  if entity.nil?
    finder_class.new(params: params).result.first
  else
    finder_class.new(entity: entity, params: params).result.first
  end
end