Class: Sequel::SQL::Constant

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

Overview

Represents constants or psuedo-constants (e.g. CURRENT_DATE) in SQL.

Direct Known Subclasses

BooleanConstant, NegativeBooleanConstant

Constant Summary

INSPECT_LOOKUPS =

Constants to lookup in the Sequel module.

[:CURRENT_DATE, :CURRENT_TIMESTAMP, :CURRENT_TIME, :SQLTRUE, :SQLFALSE, :NULL, :NOTNULL]

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

Constructor Details

#initialize(constant) ⇒ Constant

Create a constant with the given value



1229
1230
1231
1232
# File 'lib/sequel/sql.rb', line 1229

def initialize(constant)
  @constant = constant
  freeze
end

Instance Attribute Details

#constantObject (readonly)

The underlying constant related to this object.



1226
1227
1228
# File 'lib/sequel/sql.rb', line 1226

def constant
  @constant
end

Instance Method Details

#inspectObject

Reference the constant in the Sequel module if there is one that matches.



106
107
108
109
110
111
# File 'lib/sequel/extensions/eval_inspect.rb', line 106

def inspect
  INSPECT_LOOKUPS.each do |c|
    return "Sequel::#{c}" if Sequel.const_get(c) == self
  end
  super
end