Module: Sequel::Postgres::InetDatabaseMethods
- Defined in:
- lib/sequel/extensions/pg_inet.rb
Overview
Methods enabling Database object integration with the inet/cidr types.
Class Method Summary collapse
- 
  
    
      .extended(db)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Reset the conversion procs when extending the Database object, so it will pick up the inet/cidr converter. 
Instance Method Summary collapse
- 
  
    
      #bound_variable_arg(arg, conn)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Convert an IPAddr arg to a string. 
Class Method Details
.extended(db) ⇒ Object
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.
| 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # File 'lib/sequel/extensions/pg_inet.rb', line 40 def self.extended(db) db.instance_exec do extend_datasets(InetDatasetMethods) # :nocov: if !defined?(SEQUEL_PG_VERSION_INTEGER) || SEQUEL_PG_VERSION_INTEGER >= 11300 # :nocov: # sequel_pg 1.13.0+ will use inet/cidr conversion procs, but doing so is # slower, so don't add the conversion procs if using sequel_pg 1.13.0+. meth = IPAddr.method(:new) add_conversion_proc(869, meth) add_conversion_proc(650, meth) if respond_to?(:register_array_type) register_array_type('inet', :oid=>1041, :scalar_oid=>869) register_array_type('cidr', :oid=>651, :scalar_oid=>650) end end if respond_to?(:register_array_type) register_array_type('macaddr', :oid=>1040, :scalar_oid=>829) end @schema_type_classes[:ipaddr] = IPAddr end end | 
Instance Method Details
#bound_variable_arg(arg, conn) ⇒ Object
Convert an IPAddr arg to a string. Probably not necessary, but done for safety.
| 67 68 69 70 71 72 73 74 | # File 'lib/sequel/extensions/pg_inet.rb', line 67 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 |