Class: Card::Query::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/card/query/reference.rb

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' ]
}
FIELDMAP =
{
  out: [ :referer_id, :referee_id ],
  in:  [ :referee_id, :referer_id ]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, val, parent) ⇒ Reference

Returns a new instance of Reference.



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 27

def initialize key, val, parent
  key, val, @parent = key, val, 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

#cardqueryObject

Returns the value of attribute cardquery.



20
21
22
# File 'lib/card/query/reference.rb', line 20

def cardquery
  @cardquery
end

#conditionsObject

Returns the value of attribute conditions.



20
21
22
# File 'lib/card/query/reference.rb', line 20

def conditions
  @conditions
end

#infieldObject

Returns the value of attribute infield.



20
21
22
# File 'lib/card/query/reference.rb', line 20

def infield
  @infield
end

#outfieldObject

Returns the value of attribute outfield.



20
21
22
# File 'lib/card/query/reference.rb', line 20

def outfield
  @outfield
end

Instance Method Details

#table_aliasObject



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

def table_alias
  @table_alias ||= "cr#{@parent.table_id force=true}"
end