Sha256: c561717582a68c1dee18ad9527a28332a9f4d2fe8be71d29cebbfe25fad1273e

Contents?: true

Size: 887 Bytes

Versions: 5

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module Trailblazer
  class Finder
    ORM_ADAPTERS = %w[ActiveRecord Sequel].freeze
    PAGING_ADAPTERS = %w[Kaminari WillPaginate].freeze

    module Base
      def self.included(base)
        base.include Helpers::Basic
        base.include Helpers::Sorting
        base.extend Finder::Dsl
      end

      attr_reader :signal, :errors

      def initialize(options = {}) # rubocop:disable Style/OptionHash
        config = self.class.config
        ctx = {config: config, options: options}
        @signal, (ctx, *) = Activity::Find.call([ctx, {}])
        @options = options
        @errors = ctx[:errors] || {}
        @find = ctx[:finder]
      end

      def fetch_result
        result = @find.query self
        result = Utils::Array.convert_hashes_in_array_to_struct(result) if result.first.is_a?(Hash)
        result
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trailblazer-finder-0.10.0 lib/trailblazer/finder/base.rb
trailblazer-finder-0.3.0 lib/trailblazer/finder/base.rb
trailblazer-finder-0.2.7 lib/trailblazer/finder/base.rb
trailblazer-finder-0.2.6 lib/trailblazer/finder/base.rb
trailblazer-finder-0.2.5 lib/trailblazer/finder/base.rb