Module: Zonesync::Cloudflare::ProxiedSupport

Defined in:
lib/zonesync/cloudflare/proxied_support.rb

Overview

Module that adds proxied support to individual Record instances. When extended onto a record, it parses cf_tags=cf-proxied:true/false from the comment and provides a proxied accessor.

Semantics:

  • cf_tags=cf-proxied:true → explicitly enable Cloudflare proxy
  • cf_tags=cf-proxied:false → explicitly disable Cloudflare proxy
  • No cf_tags → don't touch proxied (use Cloudflare default)

Constant Summary collapse

CF_TAGS_PATTERN =
/\bcf_tags=cf-proxied:(true|false)\b/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(record) ⇒ Object



16
17
18
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 16

def self.extended(record)
  record.instance_variable_set :@original_comment, record[:comment]
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



34
35
36
37
38
39
40
41
42
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 34

def ==(other)
  other_proxied = other.respond_to?(:proxied) ? other.proxied : nil
  name == other.name &&
    type == other.type &&
    ttl == other.ttl &&
    rdata == other.rdata &&
    comment == other.comment &&
    proxied == other_proxied
end

#commentObject



24
25
26
27
28
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 24

def comment
  return @original_comment unless @original_comment&.match?(CF_TAGS_PATTERN)
  cleaned = @original_comment.sub(/\s*#{CF_TAGS_PATTERN}\s*/, " ").strip
  cleaned.empty? ? nil : cleaned
end

#hashObject



45
46
47
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 45

def hash
  [name, type, ttl, rdata, comment, proxied].hash
end

#proxiedObject



20
21
22
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 20

def proxied
  @original_comment&.match(CF_TAGS_PATTERN) { |m| m[1] == "true" }
end

#to_hObject



30
31
32
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 30

def to_h
  super.merge(comment: comment, proxied: proxied)
end

#to_sObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/zonesync/cloudflare/proxied_support.rb', line 49

def to_s
  string = [name, ttl, type, rdata].join(" ")

  comment_parts = []
  comment_parts << "cf_tags=cf-proxied:true" if proxied == true
  comment_parts << comment if comment

  string << " ; #{comment_parts.join(' ')}" if comment_parts.any?
  string
end