class Ronin::SQL::InjectionExpr

@api private

@since 1.1.0

Attributes

expression[R]

The expression that will be injected

Public Class Methods

new(initial_value) click to toggle source

Initializes the new expression to inject.

@param [String, Integer, Float, Array, Symbol] initial_value

The initial value for the expression.
# File lib/ronin/sql/injection_expr.rb, line 54
def initialize(initial_value)
  @expression = initial_value
end

Public Instance Methods

and(&block) click to toggle source

Appends an ‘AND` expression to the injection.

@yield [(self)]

The return value of the block will be used as the right-hand side
operand.  If the block accepts an argument, it will be called with
the injection expression.

@return [self]

# File lib/ronin/sql/injection_expr.rb, line 68
def and(&block)
  value = case block.arity
          when 0 then instance_eval(&block)
          else        block.call(self)
          end

  @expression = BinaryExpr.new(@expression,:AND,value)
  return self
end
or(&block) click to toggle source

Appends an ‘OR` expression to the injection.

@yield [(self)]

The return value of the block will be used as the right-hand side
operand. If the block accepts an argument, it will be called with
the injection expression.

@return [self]

# File lib/ronin/sql/injection_expr.rb, line 88
def or(&block)
  value = case block.arity
          when 0 then instance_eval(&block)
          else        block.call(self)
          end

  @expression = BinaryExpr.new(@expression,:OR,value)
  return self
end
to_sql(options={}) click to toggle source

Emits the injection expression.

@param [Hash] options

Additional options for {Emitter#initialize}.

@return [String]

The raw SQL.
# File lib/ronin/sql/injection_expr.rb, line 107
def to_sql(options={})
  emitter(options).emit(@expression)
end