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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cardqueryObject

Returns the value of attribute cardquery.



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

def cardquery
  @cardquery
end

#conditionsObject

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#infieldObject

Returns the value of attribute infield.



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

def infield
  @infield
end

#outfieldObject

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_aliasObject



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

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