Sha256: eebec7381691783b5cb2a5f6049fbfd4fee6e257f7d41acde5dd4fbc46165bc1

Contents?: true

Size: 832 Bytes

Versions: 11

Compression:

Stored size: 832 Bytes

Contents

module Kasket
  module SelectManagerMixin
    def to_kasket_query(klass, binds = [])
      begin
        query = Kasket::Visitor.new(klass, binds).accept(ast)
      rescue TypeError # unsupported object in ast
        return nil
      end

      return nil if query.nil? || query == :unsupported
      return nil if query[:attributes].blank?

      query[:index] = query[:attributes].map(&:first)

      if query[:limit]
        return nil if query[:limit] > 1
        # return nil if !query[:index].include?(:id)
      end

      if query[:index].size > 1 && query[:attributes].any? { |attribute, value| value.is_a?(Array) }
        return nil
      end

      query[:key] = klass.kasket_key_for(query[:attributes])
      query[:key] << '/first' if query[:limit] == 1 && !query[:index].include?(:id)

      query
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
kasket-4.4.3 lib/kasket/select_manager_mixin.rb
kasket-4.4.2 lib/kasket/select_manager_mixin.rb
kasket-4.4.1 lib/kasket/select_manager_mixin.rb
kasket-4.4.0 lib/kasket/select_manager_mixin.rb
kasket-4.3.0 lib/kasket/select_manager_mixin.rb
kasket-4.2.1 lib/kasket/select_manager_mixin.rb
kasket-4.2.0 lib/kasket/select_manager_mixin.rb
kasket-4.1.0 lib/kasket/select_manager_mixin.rb
kasket-4.0.1 lib/kasket/select_manager_mixin.rb
kasket-3.2.0 lib/kasket/select_manager_mixin.rb
kasket-3.1.5 lib/kasket/select_manager_mixin.rb