Class: Card::Query::Reference
Constant Summary collapse
- DEFINITIONS =
{ # syntax: # wql query key => [ direction, {reference_type} ] # direction = :out | :in # reference_type = 'L' | 'I' | 'P' refer_to: [:out, 'L', 'I'], referred_to_by: [:in, 'L', 'I'], link_to: [:out, 'L'], linked_to_by: [:in, 'L'], include: [:out, 'I'], included_by: [:in, 'I'] }.freeze
- FIELDMAP =
{ out: [:referer_id, :referee_id], in: [:referee_id, :referer_id] }.freeze
Instance Attribute Summary collapse
-
#cardquery ⇒ Object
Returns the value of attribute cardquery.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#infield ⇒ Object
Returns the value of attribute infield.
-
#outfield ⇒ Object
Returns the value of attribute outfield.
Instance Method Summary collapse
-
#initialize(key, val, parent) ⇒ Reference
constructor
A new instance of Reference.
- #table_alias ⇒ Object
Constructor Details
#initialize(key, val, parent) ⇒ Reference
Returns a new instance of Reference.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/card/query/reference.rb', line 25 def initialize key, val, parent key = key val = val @parent = parent @conditions = [] direction, *reftype = DEFINITIONS[key.to_sym] @infield, @outfield = FIELDMAP[direction] if reftype.present? operator = (reftype.size == 1 ? '=' : 'IN') quoted_letters = reftype.map { |letter| "'#{letter}'" } * ', ' @conditions << "ref_type #{operator} (#{quoted_letters})" end if val == '_none' @conditions << 'present = 0' else @cardquery = val end self end |
Instance Attribute Details
#cardquery ⇒ Object
Returns the value of attribute cardquery.
19 20 21 |
# File 'lib/card/query/reference.rb', line 19 def cardquery @cardquery end |
#conditions ⇒ Object
Returns the value of attribute conditions.
19 20 21 |
# File 'lib/card/query/reference.rb', line 19 def conditions @conditions end |
#infield ⇒ Object
Returns the value of attribute infield.
19 20 21 |
# File 'lib/card/query/reference.rb', line 19 def infield @infield end |
#outfield ⇒ Object
Returns the value of attribute outfield.
19 20 21 |
# File 'lib/card/query/reference.rb', line 19 def outfield @outfield end |
Instance Method Details
#table_alias ⇒ Object
21 22 23 |
# File 'lib/card/query/reference.rb', line 21 def table_alias @table_alias ||= "cr#{@parent.table_id force = true}" end |