Class SearchApi::SqlFragment
In: lib/search_api/sql_fragment.rb
Parent: Array

Utility class that implements logic for sql fragments (such as ["escaped_sql = ?", dirty_string])

Methods

<<   and   and!   logical_operator=   new   not   or   or!   sanitize   sanitize   sqlParameters   sqlString  

Attributes

logical_operator  [R] 

Public Class methods

[Source]

    # File lib/search_api/sql_fragment.rb, line 27
27:     def initialize(*args)
28:       if args.length > 1
29:       else
30:         args = args.first
31:       end
32:     
33:       # default operator is AND
34:       self.logical_operator = :and
35:     
36:       return if args.nil? or args.empty?
37:     
38:       if args.is_a? Array
39:         replace(args)
40:       else
41:         self.push(args)
42:       end
43:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 20
20:       def sanitize(*args)
21:         self.new(*args).sanitize
22:       end

Public Instance methods

[Source]

    # File lib/search_api/sql_fragment.rb, line 65
65:     def <<(inSqlFragment)
66:       case logical_operator
67:       when :and!, :and
68:         and!(inSqlFragment)
69:       when :or!, :or
70:         or!(inSqlFragment)
71:       else
72:         raise "Unsupported logical_operator #{logical_operator.inspect}"
73:       end
74:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 49
49:     def and(inSqlFragment)
50:       inSqlFragment = SqlFragment.new(inSqlFragment) unless inSqlFragment.is_a?(SqlFragment)
51:       return self if inSqlFragment.empty?
52:       return inSqlFragment if empty?
53:       SqlFragment(["(#{sqlString}) AND (#{inSqlFragment[0]})"] + sqlParameters + inSqlFragment[1..-1])
54:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 55
55:     def and!(inSqlFragment) replace(self.and(inSqlFragment)) end

[Source]

    # File lib/search_api/sql_fragment.rb, line 45
45:     def logical_operator=(logical_operator)
46:       @logical_operator = (logical_operator || :and)
47:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 76
76:     def not
77:       return self if empty?
78:       SqlFragment(["NOT(#{sqlString})"]+sqlParameters)
79:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 57
57:     def or(inSqlFragment)
58:       inSqlFragment = SqlFragment.new(inSqlFragment) unless inSqlFragment.is_a?(SqlFragment)
59:       return self if inSqlFragment.empty?
60:       return inSqlFragment if empty?
61:       SqlFragment(["(#{sqlString}) OR (#{inSqlFragment[0]})"] + sqlParameters + inSqlFragment[1..-1])
62:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 63
63:     def or!(inSqlFragment) replace(self.or(inSqlFragment)) end

[Source]

    # File lib/search_api/sql_fragment.rb, line 88
88:     def sanitize
89:       fragment = self
90:       ActiveRecord::Base.instance_eval do sanitize_sql(fragment) end
91:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 84
84:     def sqlParameters
85:       self[1..-1]
86:     end

[Source]

    # File lib/search_api/sql_fragment.rb, line 81
81:     def sqlString
82:       self[0]
83:     end

[Validate]