module Sequel::Postgres::InetDatabaseMethods
Methods enabling Database object integration with the inet/cidr types.
Public Class Methods
extended(db)
click to toggle source
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.
# File lib/sequel/extensions/pg_inet.rb, line 41 def self.extended(db) db.instance_eval do extend_datasets(InetDatasetMethods) copy_conversion_procs([869, 650, 1041, 651, 1040]) @schema_type_classes[:ipaddr] = IPAddr end end
Public Instance Methods
bound_variable_arg(arg, conn)
click to toggle source
Convert an IPAddr arg to a string. Probably not necessary, but done for safety.
Calls superclass method
# File lib/sequel/extensions/pg_inet.rb, line 51 def bound_variable_arg(arg, conn) case arg when IPAddr "#{arg.to_s}/#{arg.instance_variable_get(:@mask_addr).to_s(2).count('1')}" else super end end
Private Instance Methods
bound_variable_array(a)
click to toggle source
Handle inet[]/cidr types in bound variables.
Calls superclass method
# File lib/sequel/extensions/pg_inet.rb, line 63 def bound_variable_array(a) case a when IPAddr "\"#{a.to_s}/#{a.instance_variable_get(:@mask_addr).to_s(2).count('1')}\"" else super end end
schema_column_type(db_type)
click to toggle source
Make the column type detection recognize the inet and cidr types.
Calls superclass method
# File lib/sequel/extensions/pg_inet.rb, line 73 def schema_column_type(db_type) case db_type when 'inet', 'cidr' :ipaddr else super end end
typecast_value_ipaddr(value)
click to toggle source
Typecast the given value to an IPAddr object.
# File lib/sequel/extensions/pg_inet.rb, line 83 def typecast_value_ipaddr(value) case value when IPAddr value when String IPAddr.new(value) else raise Sequel::InvalidValue, "invalid value for inet/cidr: #{value.inspect}" end end