Class: Proc

Inherits:
Object show all
Defined in:
lib/sequel/extensions/sql_expr.rb

Instance Method Summary collapse

Instance Method Details

#sql_exprObject

Evaluates the proc as a virtual row block. If a hash or array of two element arrays is returned, they are converted to a Sequel::SQL::BooleanExpression. Otherwise, unless the object returned is already an Sequel::SQL::Expression, convert the object to an Sequel::SQL::GenericComplexExpression.

proc{a(b)}.sql_expr + 1  # a(b) + 1
proc{{a=>b}}.sql_expr | true  # (a = b) OR TRUE
proc{1}.sql_expr + :a  # 1 + a


89
90
91
92
93
94
95
96
97
98
# File 'lib/sequel/extensions/sql_expr.rb', line 89

def sql_expr
  o = Sequel.virtual_row(&self)
  if Sequel.condition_specifier?(o)
    Sequel::SQL::BooleanExpression.from_value_pairs(o, :AND)
  elsif o.is_a?(Sequel::SQL::Expression)
    o
  else
    Sequel::SQL::GenericComplexExpression.new(:NOOP, o)
  end
end