Sha256: c394dd3df503a97c261f650ce2980b8c24bc7c047494b53d9c6f024c1f8e3011

Contents?: true

Size: 1022 Bytes

Versions: 92

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

require "ipaddr"

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      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

92 entries across 87 versions & 9 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.0.8.7 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.0.8.6 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-6.1.7.10 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-6.1.7.9 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.0.8.5 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.1.3.4 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.0.8.4 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-6.1.7.8 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.1.3.2 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.1.3.1 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.0.8.1 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-6.1.7.7 lib/active_record/connection_adapters/postgresql/oid/cidr.rb
activerecord-7.1.3 lib/active_record/connection_adapters/postgresql/oid/cidr.rb