Class: Zonesync::Provider

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/zonesync/provider.rb

Direct Known Subclasses

Cloudflare, Filesystem, Memory, Route53

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Provider

Returns a new instance of Provider.



15
16
17
# File 'lib/zonesync/provider.rb', line 15

def initialize config
  @config = T.let(config, T::Hash[Symbol, String])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/zonesync/provider.rb', line 19

def config
  @config
end

Class Method Details

.from(config) ⇒ Object



22
23
24
# File 'lib/zonesync/provider.rb', line 22

def self.from config
  Zonesync.const_get(config.fetch(:provider)).new(config)
end

Instance Method Details

#add(record) ⇒ Object



84
85
86
# File 'lib/zonesync/provider.rb', line 84

def add record
  Kernel.raise NotImplementedError
end

#add_with_duplicate_handling(record, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/zonesync/provider.rb', line 91

def add_with_duplicate_handling record, &block
  begin
    block.call
  rescue DuplicateRecordError => e
    # Gracefully handle duplicate records - this means the record
    # already exists and we just want to start tracking it
    puts "Record already exists in #{self.class.name}: #{e.record.name} #{e.record.type} - will start tracking it"
    return
  end
end

#change(old_record, new_record) ⇒ Object



79
80
81
# File 'lib/zonesync/provider.rb', line 79

def change old_record, new_record
  Kernel.raise NotImplementedError
end

#diff(other) ⇒ Object



34
35
36
37
38
39
# File 'lib/zonesync/provider.rb', line 34

def diff other
  Diff.new(
    from: diffable_records,
    to: other.diffable_records,
  )
end

#diff!(other, force: false) ⇒ Object



27
28
29
30
31
# File 'lib/zonesync/provider.rb', line 27

def diff! other, force: false
  operations = diff(other).call
  Validator.call(operations, self, force: force)
  operations
end

#diffable_recordsObject



47
48
49
50
51
# File 'lib/zonesync/provider.rb', line 47

def diffable_records
  records.select do |record|
    manifest.diffable?(record)
  end.sort
end

#manifestObject



54
55
56
# File 'lib/zonesync/provider.rb', line 54

def manifest
  Manifest.new(records, zonefile)
end

#readObject



64
65
66
# File 'lib/zonesync/provider.rb', line 64

def read
  Kernel.raise NotImplementedError
end

#recordsObject



42
43
44
# File 'lib/zonesync/provider.rb', line 42

def records
  zonefile.records
end

#remove(record) ⇒ Object



74
75
76
# File 'lib/zonesync/provider.rb', line 74

def remove record
  Kernel.raise NotImplementedError
end

#write(string) ⇒ Object



69
70
71
# File 'lib/zonesync/provider.rb', line 69

def write string
  Kernel.raise NotImplementedError
end