Class: Sequel::Postgres::InetOp
- Inherits:
-
SQL::Wrapper
- Object
- SQL::Expression
- SQL::GenericExpression
- SQL::Wrapper
- Sequel::Postgres::InetOp
- 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 collapse
- 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
Instance Method Summary collapse
-
#-(v) ⇒ Object
Return an expression for the subtraction of the argument from the receiver.
-
#initialize(v) ⇒ InetOp
constructor
For String and IPAddr instances, wrap them in a cast to inet, to avoid ambiguity issues when calling operator methods.
-
#pg_inet ⇒ Object
Return the receiver.
-
#set_masklen(v) ⇒ Object
Return an expression for the calling of the set_masklen function with the receiver and the given argument.
-
#~ ⇒ Object
Return an expression for the bitwise NOT of the receiver.
Methods included from HStoreOpMethods
Methods included from RangeOpMethods
Methods included from ArrayOpMethods
Methods included from JSONOpMethods
Methods included from PGRowOp::ExpressionMethods
Methods included from SQL::SubscriptMethods
Methods included from SQL::StringMethods
Methods included from SQL::PatternMatchMethods
Methods included from SQL::OrderMethods
Methods included from SQL::NumericMethods
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
Methods inherited from SQL::Expression
#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal
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.
73 74 75 76 77 78 79 80 81 |
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 73 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
124 125 126 127 128 129 130 131 |
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 124 def -(v) case v when Integer self.class.new(super) else Sequel::SQL::NumericExpression.new(:NOOP, super) end end |
#pg_inet ⇒ Object
Return the receiver.
114 115 116 |
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 114 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
134 135 136 |
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 134 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
119 120 121 |
# File 'lib/sequel/extensions/pg_inet_ops.rb', line 119 def ~ self.class.new(super) end |