Class: GitHubPages::HealthCheck::CloudFlare
- Inherits:
-
Object
- Object
- GitHubPages::HealthCheck::CloudFlare
- Includes:
- Singleton
- Defined in:
- lib/github-pages-health-check/cloudflare.rb
Constant Summary collapse
- CONFIG_PATH =
File.("../../config/cloudflare-ips.txt", File.dirname(__FILE__))
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Internal: The path of the config file.
Class Method Summary collapse
-
.controls_ip?(address) ⇒ Boolean
Public: Does cloudflare control this address?.
Instance Method Summary collapse
-
#controls_ip?(address) ⇒ Boolean
Internal: Does cloudflare control this address?.
-
#initialize(options = {}) ⇒ CloudFlare
constructor
Internal: Create a new cloudflare info instance.
-
#load_ranges ⇒ Object
Internal: Load IPAddr ranges from #path.
-
#ranges ⇒ Object
Internal: The IP address ranges that cloudflare controls.
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( = {}) @path = .fetch(:path) { CONFIG_PATH } end |
Instance Attribute Details
#path ⇒ Object (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?
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?
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_ranges ⇒ Object
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 |
#ranges ⇒ Object
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 |