Sha256: a56b3c915e4da2f6cc7ddb7c069d4473a71ed859e7b09759ad91705c7c226b27

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

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

module Trailblazer
  class Finder
    module Adapters
      # Sequel Adapter
      module Sequel
        def self.included(base)
          base.extend ClassMethods
          base.instance_eval do
            include Sequel::Predicates if defined?(Features::Predicate::ClassMethods)
          end
          # require 'trailblazer/finder/adapters/sequel/predicates' if defined?(Features::Predicates::ClassMethods)
        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/sequel.rb
trailblazer-finder-0.1.2 lib/trailblazer/finder/adapters/sequel.rb