Sha256: c534517e51858034ea85b0a95b66aab09172bf60e698413db104ebb339001d9e

Contents?: true

Size: 817 Bytes

Versions: 4

Compression:

Stored size: 817 Bytes

Contents

# frozen_string_literal: true

class Core::Repositories::<%= @scope_class %>::<%= @repository_class%> < Core::Repositories::AbstractRepository
  def initialize(params:)
    @params = prepare! params, sanitize: true
    build_pagination_variable! @params
  end

  def call(builder: true)
    resources = <%= @model_class %>
    if @search.present?
      resources = resources.where('<%= @search_able.map { |field| "LOWER(#{field}) LIKE :search" }.join(' OR ')%>', search: "%#{search}%")
    end
    return Success [] unless resources.present?
    pagy, results = pagy(resources.order(created_at: :desc), limit: @per_page, page: @page)
    response      = results.map { |result| Core::Builders::<%= @subject_class %>.new(result).build }
    Success Hashie::Mash.new(response: response, meta: paginate!(pagy))
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rider-kick-0.0.5 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
rider-kick-0.0.4 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
rider-kick-0.0.3 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
rider-kick-0.0.2 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt