Sha256: a2788a53339ccfbf41024e9b3f31598029cb6a220036c8d81609e393ad9ee975

Contents?: true

Size: 997 Bytes

Versions: 16

Compression:

Stored size: 997 Bytes

Contents

class GitHubPages
  class HealthCheck
    class CloudFlare
      include Singleton

      CONFIG_PATH = File.expand_path("../../config/cloudflare-ips.txt", File.dirname(__FILE__))

      # 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) { CONFIG_PATH }
      end

      # Internal: The path of the config file.
      attr_reader :path

      # Internal: Does cloudflare control this address?
      def controls_ip?(address)
        ranges.any? { |range| range.include?(address) }
      end

      # 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
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
github-pages-health-check-0.6.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.6.0 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.5.3 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.5.2 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.5.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.5.0 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.4.2 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.4.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.4.0 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.3.2 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.3.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.3.0 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.2.2 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.2.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.1.1 lib/github-pages-health-check/cloudflare.rb
github-pages-health-check-0.1.0 lib/github-pages-health-check/cloudflare.rb