Sha256: 93aa7f9b8df11af8f9fe4cd7886019afee1dd6f2839b9695e25f62f9e4fa2f96

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 KB

Contents

require 'ipaddr'
require 'forwardable'

module Middleman
  class PreviewServer
    class ServerIpAddress
      def self.new(ip_address)
        @parser = []
        @parser << ServerIpv6Address
        @parser << ServerIpv4Address

        @parser.find { |p| p.match? ip_address }.new(ip_address)
      end
    end

    class BasicServerIpAddress < SimpleDelegator
    end

    class ServerIpv4Address < BasicServerIpAddress
      def to_browser
        __getobj__.to_s
      end

      def self.match?(*)
        true
      end
    end

    class ServerIpv6Address < BasicServerIpAddress
      def to_s
        __getobj__.sub(/%.*$/, '')
      end

      def to_browser
        format('[%s]', to_s)
      end

      if RUBY_VERSION < '2'
        def self.match?(str)
          str = str.to_s.sub(/%.*$/, '')
          IPAddr.new(str).ipv6?
        rescue StandardError
          false
        end
      else
        def self.match?(str)
          str = str.to_s.sub(/%.*$/, '')
          IPAddr.new(str).ipv6?
        rescue IPAddr::InvalidAddressError, IPAddr::AddressFamilyError
          false
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
middleman-core-4.3.11 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.10 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.8 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.7 lib/middleman-core/preview_server/server_ip_address.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/middleman-core-4.3.3/lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.6 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.5 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.4 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.3 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.2 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.1 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.0 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.0.rc.4 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.0.rc.3 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.0.rc.2 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-with-external-sources-watch-fix-4.1.10 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-with-external-sources-watch-fix-4.1.0 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.3.0.rc.1 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.2.1 lib/middleman-core/preview_server/server_ip_address.rb
middleman-core-4.2.0 lib/middleman-core/preview_server/server_ip_address.rb