Sha256: 1e1f6b03dc124912f19194dbcc670b729232fecaec4c13cea570795af73ba22a

Contents?: true

Size: 1 KB

Versions: 66

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "ipaddr"

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      module OID # :nodoc:
        class Cidr < Type::Value # :nodoc:
          def type
            :cidr
          end

          def type_cast_for_schema(value)
            # If the subnet mask is equal to /32, don't output it
            if value.prefix == 32
              "\"#{value}\""
            else
              "\"#{value}/#{value.prefix}\""
            end
          end

          def serialize(value)
            if IPAddr === value
              "#{value}/#{value.prefix}"
            else
              value
            end
          end

          def cast_value(value)
            if value.nil?
              nil
            elsif String === value
              begin
                IPAddr.new(value)
              rescue ArgumentError
                nil
              end
            else
              value
            end
          end
        end
      end
    end
  end
end

Version data entries

66 entries across 32 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.7.17 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.17 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.16 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.16 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.15 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.15 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.14 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.14 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.12 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.12 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.11 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.11 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.10 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.10 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.9 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.9 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.8 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.8 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.7 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
activerecord-cipherstash-pg-adapter-0.7.7 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb