Class: GitHubPages::HealthCheck::CloudFlare

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/github-pages-health-check/cloudflare.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CloudFlare

Internal: Create a new cloudflare info instance.



14
15
16
# File 'lib/github-pages-health-check/cloudflare.rb', line 14

def initialize(options = {})
  @path = options.fetch(:path) { CONFIG_PATH }
end

Instance Attribute Details

#pathObject (readonly)

Internal: The path of the config file.



19
20
21
# File 'lib/github-pages-health-check/cloudflare.rb', line 19

def path
  @path
end

Class Method Details

.controls_ip?(address) ⇒ Boolean

Public: Does cloudflare control this address?

Returns:

  • (Boolean)


9
10
11
# File 'lib/github-pages-health-check/cloudflare.rb', line 9

def self.controls_ip?(address)
  instance.controls_ip?(address)
end

Instance Method Details

#controls_ip?(address) ⇒ Boolean

Internal: Does cloudflare control this address?

Returns:

  • (Boolean)


22
23
24
# File 'lib/github-pages-health-check/cloudflare.rb', line 22

def controls_ip?(address)
  ranges.any? { |range| range.include?(address) }
end

#load_rangesObject

Internal: Load IPAddr ranges from #path



32
33
34
# File 'lib/github-pages-health-check/cloudflare.rb', line 32

def load_ranges
  File.read(path).lines.map { |line| IPAddr.new(line.chomp) }
end

#rangesObject

Internal: The IP address ranges that cloudflare controls.



27
28
29
# File 'lib/github-pages-health-check/cloudflare.rb', line 27

def ranges
  @ranges ||= load_ranges
end