Sha256: 5dce18edbd5c75d39aafe6170355609a16dd48c42aea6fe0af4a6bdf1f028d6d
Contents?: true
Size: 584 Bytes
Versions: 5
Compression:
Stored size: 584 Bytes
Contents
# frozen_string_literal: true module Mongoid module Orderable module Generators class Scope < Base def generate(field_name, order_scope) criteria = criteria(order_scope) klass.class_eval do scope "orderable_#{field_name}_scope", criteria end end protected def criteria(order_scope) case order_scope when Proc then order_scope when Array then ->(doc) { where(order_scope.each_with_object({}) {|f, h| h[f] = doc.send(f) }) } else ->(_doc) { where({}) } end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems