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.



27
28
29
# File 'lib/glare/cf_dns_records.rb', line 27

def initialize(records)
  @records = records
end

Class Method Details

.emptyObject



22
23
24
# File 'lib/glare/cf_dns_records.rb', line 22

def empty
  new([])
end

.from_result(api_response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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']
    )
  end

  new(records)
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/glare/cf_dns_records.rb', line 51

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

#calculate(desired_records) ⇒ Object



31
32
33
# File 'lib/glare/cf_dns_records.rb', line 31

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

#contentsObject



39
40
41
# File 'lib/glare/cf_dns_records.rb', line 39

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

#delete_ifObject



55
56
57
# File 'lib/glare/cf_dns_records.rb', line 55

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

#dupObject



35
36
37
# File 'lib/glare/cf_dns_records.rb', line 35

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

#eachObject



43
44
45
# File 'lib/glare/cf_dns_records.rb', line 43

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

#mapObject



47
48
49
# File 'lib/glare/cf_dns_records.rb', line 47

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