Sha256: 8dd4d28165b3196950e9d1142c0a831f52dfb557546c2f479f5cfd7f82c3d113

Contents?: true

Size: 1.27 KB

Versions: 32

Compression:

Stored size: 1.27 KB

Contents

class Card
  module Query
    # support the use of the card_references table in CQL
    class ReferenceQuery < AbstractQuery
      def table
        "card_references"
      end

      def table_prefix
        "cr"
      end

      def referer hash
        add_conditions :referer_id, hash
      end

      def referee hash
        add_conditions :referee_id, hash
      end

      def add_conditions outfield, hash
        add_reftype_condition hash[:reftype]
        add_outfield_condition outfield, hash[:card]
      end

      def add_outfield_condition outfield, outcard
        if outcard == "_none"
          non_outfield
        elsif (id = id_from_val(outcard))
          outfield_id outfield, id
        else
          tie :card, outcard, from: outfield
        end
      end

      def non_outfield
        add_condition "#{fld :is_present} = 0"
      end

      def outfield_id outfield, id
        add_condition "#{fld(outfield)} = #{id}"
      end

      def add_reftype_condition reftype
        return unless reftype.present?

        reftype = Array.wrap reftype
        operator = (reftype.size == 1 ? "=" : "IN")
        quoted_letters = reftype.map { |letter| "'#{letter}'" } * ", "
        add_condition "#{fld(:ref_type)} #{operator} (#{quoted_letters})"
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
card-1.105.6 lib/card/query/reference_query.rb
card-1.105.5 lib/card/query/reference_query.rb
card-1.105.4 lib/card/query/reference_query.rb
card-1.105.3 lib/card/query/reference_query.rb
card-1.105.2.pre1 lib/card/query/reference_query.rb
card-1.105.2 lib/card/query/reference_query.rb
card-1.105.1 lib/card/query/reference_query.rb
card-1.105.0 lib/card/query/reference_query.rb
card-1.104.2 lib/card/query/reference_query.rb
card-1.104.1 lib/card/query/reference_query.rb
card-1.104.0 lib/card/query/reference_query.rb
card-1.103.4 lib/card/query/reference_query.rb
card-1.103.3 lib/card/query/reference_query.rb
card-1.103.2 lib/card/query/reference_query.rb
card-1.103.1 lib/card/query/reference_query.rb
card-1.103.0 lib/card/query/reference_query.rb
card-1.101.7 lib/card/query/reference_query.rb
card-1.102.0 lib/card/query/reference_query.rb
card-1.101.6 lib/card/query/reference_query.rb
card-1.101.5 lib/card/query/reference_query.rb