Sha256: fb952abce34d9f209f6879675df3b2ad2eaeda9894b048d873f536c598f95a7b
Contents?: true
Size: 1.03 KB
Versions: 5
Compression:
Stored size: 1.03 KB
Contents
module GitHubPages module HealthCheck class CloudFlare include Singleton # Internal: The path of the config file. attr_reader :path # Public: Does cloudflare control this address? def self.controls_ip?(address) instance.controls_ip?(address) end # Internal: Create a new cloudflare info instance. def initialize(options = {}) @path = options.fetch(:path) { default_config_path } end # Internal: Does cloudflare control this address? def controls_ip?(address) ranges.any? { |range| range.include?(address) } end private # Internal: The IP address ranges that cloudflare controls. def ranges @ranges ||= load_ranges end # Internal: Load IPAddr ranges from #path def load_ranges File.read(path).lines.map { |line| IPAddr.new(line.chomp) } end def default_config_path File.expand_path("../../config/cloudflare-ips.txt", File.dirname(__FILE__)) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems