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