Class: RecordStore::Zone
- Inherits:
-
Object
show all
- Extended by:
- YamlDefinitions
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/record_store/zone.rb,
lib/record_store/zone/config.rb,
lib/record_store/zone/yaml_definitions.rb
Defined Under Namespace
Modules: YamlDefinitions
Classes: Config
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
[], all, defined, each, find, reset
Constructor Details
#initialize(name:, records: [], config: {}) ⇒ Zone
Returns a new instance of Zone.
56
57
58
59
60
|
# File 'lib/record_store/zone.rb', line 56
def initialize(name:, records: [], config: {})
@name = Record.ensure_ends_with_dot(name)
@config = RecordStore::Zone::Config.new(config.deep_symbolize_keys)
@records = build_records(records)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7
8
9
|
# File 'lib/record_store/zone.rb', line 7
def config
@config
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/record_store/zone.rb', line 6
def name
@name
end
|
Class Method Details
.download(name, provider_name, **write_options) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/record_store/zone.rb', line 21
def download(name, provider_name, **write_options)
zone = Zone.new(name: name, config: {providers: [provider_name]})
raise ArgumentError, zone.errors.full_messages.join("\n") unless zone.valid?
zone.records = zone.providers.first.retrieve_current_records(zone: name)
zone.config = Zone::Config.new(
providers: [provider_name],
ignore_patterns: [{type: "NS", fqdn: "#{name}."}],
supports_alias: (zone.records.map(&:type).include?('ALIAS') || nil)
)
zone.write(**write_options)
end
|
.filter_records(current_records, ignore_patterns) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/record_store/zone.rb', line 36
def filter_records(current_records, ignore_patterns)
ignore_patterns.inject(current_records) do |remaining_records, pattern|
remaining_records.reject do |record|
pattern.all? { |(key, value)| record.respond_to?(key) && value === record.send(key) }
end
end
end
|
.modified ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/record_store/zone.rb', line 44
def modified
modified_zones, mutex = [], Mutex.new
self.all.map do |zone|
thread = Thread.new do
mutex.synchronize {modified_zones << zone} unless zone.unchanged?
end
end.each(&:join)
modified_zones
end
|
Instance Method Details
#build_changesets ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/record_store/zone.rb', line 62
def build_changesets
@changesets ||= begin
providers.map do |provider|
Changeset.build_from(provider: provider, zone: self)
end
end
end
|
#providers ⇒ Object
92
93
94
|
# File 'lib/record_store/zone.rb', line 92
def providers
@providers ||= config.providers.map { |provider| Provider.const_get(provider) }
end
|
#records ⇒ Object
78
79
80
|
# File 'lib/record_store/zone.rb', line 78
def records
@records_cache ||= Zone.filter_records(@records, config.ignore_patterns)
end
|
#records=(records) ⇒ Object
82
83
84
85
|
# File 'lib/record_store/zone.rb', line 82
def records=(records)
@records_cache = nil
@records = records
end
|
#unchanged? ⇒ Boolean
70
71
72
|
# File 'lib/record_store/zone.rb', line 70
def unchanged?
build_changesets.all?(&:empty?)
end
|
#unrooted_name ⇒ Object
74
75
76
|
# File 'lib/record_store/zone.rb', line 74
def unrooted_name
@name.chomp('.')
end
|
#write(**write_options) ⇒ Object
96
97
98
|
# File 'lib/record_store/zone.rb', line 96
def write(**write_options)
self.class.write(name, config: config, records: records, **write_options)
end
|