Class: Sequel::SQL::DelayedEvaluation

Inherits:
GenericExpression show all
Defined in:
lib/sequel/sql.rb

Overview

Represents a delayed evaluation, encapsulating a callable object which returns the value to use when called.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Postgres::HStoreOpMethods

#hstore

Methods included from Postgres::RangeOpMethods

#pg_range

Methods included from Postgres::ArrayOpMethods

#pg_array

Methods included from Postgres::JSONOpMethods

#pg_json, #pg_jsonb

Methods included from Postgres::InetOpMethods

#pg_inet

Methods included from Postgres::PGRowOp::ExpressionMethods

#pg_row

Methods included from SubscriptMethods

#sql_subscript

Methods included from StringMethods

#ilike, #like

Methods included from PatternMatchMethods

#!~, #=~

Methods included from OrderMethods

#asc, #desc

Methods included from NumericMethods

#+, #coerce

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from BooleanMethods

#~

Methods included from AliasMethods

#as

Methods inherited from Expression

#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect

Constructor Details

#initialize(callable) ⇒ DelayedEvaluation

Set the callable object


1276
1277
1278
1279
# File 'lib/sequel/sql.rb', line 1276

def initialize(callable)
  @callable = callable
  freeze
end

Instance Attribute Details

#callableObject (readonly)

A callable object that returns the value of the evaluation when called.


1273
1274
1275
# File 'lib/sequel/sql.rb', line 1273

def callable
  @callable
end

Instance Method Details

#call(ds) ⇒ Object

Call the underlying callable and return the result. If the underlying callable only accepts a single argument, call it with the given dataset.


1284
1285
1286
1287
1288
1289
1290
# File 'lib/sequel/sql.rb', line 1284

def call(ds)
  if @callable.respond_to?(:arity) && @callable.arity == 1
    @callable.call(ds)
  else
    @callable.call
  end
end