Class: Zonesync::Provider

Inherits:
Object
  • Object
show all
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.



11
12
13
# File 'lib/zonesync/provider.rb', line 11

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Class Method Details

.from(config) ⇒ Object



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

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

Instance Method Details

#add(record) ⇒ Object

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/zonesync/provider.rb', line 67

def add(record)
  raise NotImplementedError
end

#add_with_duplicate_handling(record, &block) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/zonesync/provider.rb', line 71

def add_with_duplicate_handling(record, &block)
  begin
    block.call
  rescue DuplicateRecordError => e
    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

Raises:

  • (NotImplementedError)


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

def change(old_record, new_record)
  raise NotImplementedError
end

#diff(other) ⇒ Object



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

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

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



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

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

#diffable_recordsObject



37
38
39
40
41
# File 'lib/zonesync/provider.rb', line 37

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

#manifestObject



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

def manifest
  Manifest.new(records, zonefile)
end

#readObject

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/zonesync/provider.rb', line 51

def read
  raise NotImplementedError
end

#recordsObject



33
34
35
# File 'lib/zonesync/provider.rb', line 33

def records
  zonefile.records
end

#remove(record) ⇒ Object

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/zonesync/provider.rb', line 59

def remove(record)
  raise NotImplementedError
end

#write(string) ⇒ Object

Raises:

  • (NotImplementedError)


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

def write(string)
  raise NotImplementedError
end