module Sequel::Postgres::InetDatabaseMethods

  1. lib/sequel/extensions/pg_inet.rb

Methods enabling Database object integration with the inet/cidr types.

Methods

Public Class

  1. extended

Public Instance

  1. bound_variable_arg

Public Class methods

extended(db)

Reset the conversion procs when extending the Database object, so it will pick up the inet/cidr converter. Also, extend the datasets with support for literalizing the IPAddr types.

[show source]
   # File lib/sequel/extensions/pg_inet.rb
40 def self.extended(db)
41   db.instance_exec do
42     extend_datasets(InetDatasetMethods)
43 
44     # :nocov:
45     if !defined?(SEQUEL_PG_VERSION_INTEGER) || SEQUEL_PG_VERSION_INTEGER >= 11300
46     # :nocov:
47       # sequel_pg 1.13.0+ will use inet/cidr conversion procs, but doing so is
48       # slower, so don't add the conversion procs if using sequel_pg 1.13.0+.
49       meth = IPAddr.method(:new)
50       add_conversion_proc(869, meth)
51       add_conversion_proc(650, meth)
52       if respond_to?(:register_array_type)
53         register_array_type('inet', :oid=>1041, :scalar_oid=>869)
54         register_array_type('cidr', :oid=>651, :scalar_oid=>650)
55       end
56     end
57 
58     if respond_to?(:register_array_type)
59       register_array_type('macaddr', :oid=>1040, :scalar_oid=>829)
60     end
61     @schema_type_classes[:ipaddr] = IPAddr
62   end
63 end

Public Instance methods

bound_variable_arg(arg, conn)

Convert an IPAddr arg to a string. Probably not necessary, but done for safety.

[show source]
   # File lib/sequel/extensions/pg_inet.rb
67 def bound_variable_arg(arg, conn)
68   case arg
69   when IPAddr
70     "#{arg.to_s}/#{arg.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
71   else
72     super
73   end
74 end