Sha256: 5f0dcdbbb5aaf1ac490635c10ba5e019da2c016f84dbbfafb7c0e12a71477e54

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'trailblazer/finder/adapters/active_record/paging'
require 'trailblazer/finder/adapters/active_record/sorting'
require 'trailblazer/finder/adapters/active_record/predicates'

module Trailblazer
  class Finder
    module Adapters
      # ActiveRecord Adapter
      module ActiveRecord
        def self.included(base)
          base.extend ClassMethods
          base.instance_eval do
            include ActiveRecord::Predicates if defined?(Features::Predicate::ClassMethods)
          end
        end

        module ClassMethods
          # :nocov:
          def normalize_find_handler(handler, key)
            case handler
            when Symbol then ->(entity_type, value) { method(handler).call entity_type, value }
            when Proc then handler
            else ->(entity_type, value) { entity_type.where(key.to_sym => value) unless Utils::String.blank?(value) }
            end
          end
          # :nocov:
        end

        include Paging if defined?(Features::Paging::ClassMethods)
        include Sorting if defined?(Features::Sorting::ClassMethods)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trailblazer-finder-0.1.3 lib/trailblazer/finder/adapters/active_record.rb
trailblazer-finder-0.1.2 lib/trailblazer/finder/adapters/active_record.rb