class Trailblazer::Finder::Find

Attributes

config[R]
filters[R]
paging[R]
params[R]
sorting[R]

Public Class Methods

new(entity, params, filters, paging = nil, sorting = nil, config = nil) click to toggle source
# File lib/trailblazer/finder/find.rb, line 8
def initialize(entity, params, filters, paging = nil, sorting = nil, config = nil)
  @entity   = entity
  @filters  = filters
  @params   = params
  @paging   = paging || {}
  @sorting = sorting || {}
  @config = config || {}
end

Public Instance Methods

process_filters(ctx) click to toggle source
# File lib/trailblazer/finder/find.rb, line 17
def process_filters(ctx)
  @params.reduce(@entity) do |entity, (name, value)|
    value = Utils::String.to_date(value) if Utils::String.date?(value)
    filter = @filters[name.to_sym] || @filters[name]
    new_entity = ctx.instance_exec entity, filter[:name], value, &filter[:handler]
    new_entity || entity
  end
end
process_paging(ctx) click to toggle source
# File lib/trailblazer/finder/find.rb, line 26
def process_paging(ctx)
  ctx.instance_exec @paging[:current_page], @paging[:per_page], (@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler]
end
process_sorting(ctx) click to toggle source
# File lib/trailblazer/finder/find.rb, line 30
def process_sorting(ctx)
  ctx.instance_exec @sorting, (process_filters ctx), &@sorting[:handler]
end
query(ctx) click to toggle source
# File lib/trailblazer/finder/find.rb, line 34
def query(ctx)
  return process_paging ctx unless @paging.empty? || @paging.nil?
  return process_sorting ctx unless @sorting.empty? || @sorting.nil?

  process_filters ctx
end