Class: Card::Query::ReferenceQuery

Inherits:
AbstractQuery show all
Defined in:
card/lib/card/query/reference_query.rb

Overview

support the use of the card_references table in CQL

Constant Summary

Constants inherited from AbstractQuery

AbstractQuery::ROOT_VAR_DEFAULTS

Instance Attribute Summary

Attributes inherited from AbstractQuery

#comment, #conditions, #conditions_on_join, #joins, #mods, #negate, #statement, #subqueries, #superquery, #table_suffix, #vars

Instance Method Summary collapse

Methods inherited from AbstractQuery

#context, #depth, #full?, #initialize, #interpret, #root, #root?, #sql, #sql_statement, #subquery

Methods included from AbstractQuery::Tie

#fasten, #fasten_tie, #id_from_val, #inherit_fasten, #left_join?, #list_of_ids?, #negate_join, #op_and_id_or_ids_from_val, #restrict, #super_conditions, #superfield, #tie, #tie_subquery, #tie_with_exist, #tie_with_in, #tie_with_join, #tie_with_join_args

Methods included from AbstractQuery::QueryHelper

#add_condition, #current_conjunction, #direct_subqueries, #fld, #subqueries_with_fasten, #table_alias, #table_seq

Constructor Details

This class inherits a constructor from Card::Query::AbstractQuery

Instance Method Details

#add_conditions(outfield, hash) ⇒ Object



21
22
23
24
# File 'card/lib/card/query/reference_query.rb', line 21

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

#add_outfield_condition(outfield, outcard) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'card/lib/card/query/reference_query.rb', line 26

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

#add_reftype_condition(reftype) ⇒ Object



44
45
46
47
48
49
50
51
# File 'card/lib/card/query/reference_query.rb', line 44

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

#non_outfieldObject



36
37
38
# File 'card/lib/card/query/reference_query.rb', line 36

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

#outfield_id(outfield, op_and_id) ⇒ Object



40
41
42
# File 'card/lib/card/query/reference_query.rb', line 40

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

#referee(hash) ⇒ Object



17
18
19
# File 'card/lib/card/query/reference_query.rb', line 17

def referee hash
  add_conditions :referee_id, hash
end

#referer(hash) ⇒ Object



13
14
15
# File 'card/lib/card/query/reference_query.rb', line 13

def referer hash
  add_conditions :referer_id, hash
end

#tableObject



5
6
7
# File 'card/lib/card/query/reference_query.rb', line 5

def table
  "card_references"
end

#table_prefixObject



9
10
11
# File 'card/lib/card/query/reference_query.rb', line 9

def table_prefix
  "cr"
end