Class: Zena::Use::QueryComment::Compiler

Inherits:
QueryBuilder::Processor
  • Object
show all
Defined in:
lib/zena/use/query_comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#node_nameObject (readonly)

Returns the value of attribute node_name.



33
34
35
# File 'lib/zena/use/query_comment.rb', line 33

def node_name
  @node_name
end

Instance Method Details

#map_attr(fld) ⇒ Object



79
80
81
82
# File 'lib/zena/use/query_comment.rb', line 79

def map_attr(fld)
  # error
  nil
end

#map_literal(value) ⇒ Object

Same as QueryNode… DRY needed.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/zena/use/query_comment.rb', line 39

def map_literal(value)
  if value =~ /(.*?)\[(node|visitor|param):(\w+)\](.*)/
    val_start = $1 == '' ? '' : "#{$1.inspect} +"
    val_end   = $4 == '' ? '' : "+ #{$4.inspect}"
    case $2
    when 'visitor'
      if $3 == 'user_id'
        value = "visitor.id"
      else
        value = "Node.zafu_attribute(visitor.node, #{$3.inspect})"
      end
    when 'node'
      if $3 == 'user_id'
        value = "#{@node_name}.user_id"
      else
        value = "Node.zafu_attribute(#{@node_name}, #{$3.inspect})"
      end
    when 'param'
      return "\#{Node.connection.quote(#{val_start}params[:#{$3}].to_s#{val_end})}"
    end

    if !val_start.blank? || !val_end.blank?
      "\#{Node.connection.quote(#{val_start}#{value}#{val_end})}"
    else
      "\#{#{value}}"
    end
  else
    value = Node.connection.quote(value)
  end
end

#process_field(field_name) ⇒ Object

Overwrite this and take car to check for valid fields.



71
72
73
74
75
76
77
# File 'lib/zena/use/query_comment.rb', line 71

def process_field(field_name)
  if %w{status updated_at author_name created_at title text author_id}.include?(field_name)
    "#{table}.#{field_name}"
  else
    super # raise an error
  end
end