Sha256: 7c8317896499b560ada7be0448ff00150a6cf8f6688fd2a754c775cbfcf35b25

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

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

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

        module ClassMethods
          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.all(key.to_sym => value) unless Utils::String.blank?(value) }
            end
          end
        end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-finder-0.1.4 lib/trailblazer/finder/adapters/data_mapper.rb