Class: Glare::CfDnsRecords

Inherits:
Object
  • Object
show all
Defined in:
lib/glare/cf_dns_records.rb,
lib/glare/cf_dns_records/updater.rb

Defined Under Namespace

Classes: Updater

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ CfDnsRecords

Returns a new instance of CfDnsRecords.



29
30
31
# File 'lib/glare/cf_dns_records.rb', line 29

def initialize(records)
  @records = records
end

Class Method Details

.emptyObject



24
25
26
# File 'lib/glare/cf_dns_records.rb', line 24

def empty
  new([])
end

.from_result(api_response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/glare/cf_dns_records.rb', line 7

def from_result(api_response)
  result = api_response.result

  records = result.map do |item|
    CfDnsRecord.new(
      id: item['id'],
      name: item['name'],
      type: item['type'],
      content: item['content'],
      proxied: item['proxied'],
      ttl: item['ttl']
    )
  end

  new(records)
end

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/glare/cf_dns_records.rb', line 49

def all?
  @records.all? { |record| yield(record) }
end

#all_proxied?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/glare/cf_dns_records.rb', line 45

def all_proxied?
  @records.all? { |r| r.proxied == true }
end

#any?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/glare/cf_dns_records.rb', line 61

def any?
  @records.any? { |record| yield(record) }
end

#calculate(desired_records) ⇒ Object



33
34
35
# File 'lib/glare/cf_dns_records.rb', line 33

def calculate(desired_records)
  Updater.new(@records.dup, desired_records.dup).calculate
end

#contentsObject



41
42
43
# File 'lib/glare/cf_dns_records.rb', line 41

def contents
  @records.map(&:content)
end

#delete_ifObject



65
66
67
# File 'lib/glare/cf_dns_records.rb', line 65

def delete_if
  @records.delete_if { |record| yield(record) }
end

#dupObject



37
38
39
# File 'lib/glare/cf_dns_records.rb', line 37

def dup
  CfDnsRecords.new(@records.dup)
end

#eachObject



53
54
55
# File 'lib/glare/cf_dns_records.rb', line 53

def each
  @records.each { |record| yield(record) }
end

#mapObject



57
58
59
# File 'lib/glare/cf_dns_records.rb', line 57

def map
  @records.map { |record| yield(record) }
end