Class: Sequel::Postgres::InetOp

Inherits:
SQL::Wrapper show all
Includes:
SQL::BitwiseMethods
Defined in:
lib/sequel/extensions/pg_inet_ops.rb

Overview

The InetOp class is a simple container for a single object that defines methods that yield Sequel expression objects representing PostgreSQL inet operators and functions.

Most methods in this class are defined via metaprogramming, see the pg_inet_ops extension documentation for details on the API.

Constant Summary

OPERATORS =
{
  :contained_by_or_equals => ["(".freeze, " <<= ".freeze, ")".freeze].freeze,
  :contains_or_equals => ["(".freeze, " >>= ".freeze, ")".freeze].freeze,
  :contains_or_contained_by => ["(".freeze, " && ".freeze, ")".freeze].freeze,
}.freeze

Instance Attribute Summary

Attributes inherited from SQL::Wrapper

#value

Instance Method Summary collapse

Methods included from HStoreOpMethods

#hstore

Methods included from RangeOpMethods

#pg_range

Methods included from ArrayOpMethods

#pg_array

Methods included from JSONOpMethods

#pg_json, #pg_jsonb

Methods included from PGRowOp::ExpressionMethods

#pg_row

Methods included from SQL::SubscriptMethods

#sql_subscript

Methods included from SQL::StringMethods

#ilike, #like

Methods included from SQL::PatternMatchMethods

#!~, #=~

Methods included from SQL::OrderMethods

#asc, #desc

Methods included from SQL::NumericMethods

#+, #coerce

Methods included from SQL::ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from SQL::CastMethods

#cast, #cast_numeric, #cast_string

Methods included from SQL::AliasMethods

#as

Methods inherited from SQL::Expression

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

Constructor Details

#initialize(v) ⇒ InetOp

For String and IPAddr instances, wrap them in a cast to inet, to avoid ambiguity issues when calling operator methods.



77
78
79
80
81
82
83
84
85
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 77

def initialize(v)
  case v
  when ::Sequel::LiteralString
    # nothing
  when String, IPAddr
    v = Sequel.cast(v, :inet)
  end
  super
end

Instance Method Details

#-(v) ⇒ Object

Return an expression for the subtraction of the argument from the receiver



128
129
130
131
132
133
134
135
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 128

def -(v)
  case v
  when Integer
    self.class.new(super)
  else
    Sequel::SQL::NumericExpression.new(:NOOP, super)
  end
end

#pg_inetObject

Return the receiver.



118
119
120
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 118

def pg_inet
  self
end

#set_masklen(v) ⇒ Object

Return an expression for the calling of the set_masklen function with the receiver and the given argument



138
139
140
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 138

def set_masklen(v)
  self.class.new(Sequel::SQL::Function.new(:set_masklen, self, v))
end

#~Object

Return an expression for the bitwise NOT of the receiver



123
124
125
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 123

def ~
  self.class.new(super)
end