Module: RecordStore::Zone::YamlDefinitions
- Includes:
- Enumerable
- Included in:
- RecordStore::Zone
- Defined in:
- lib/record_store/zone/yaml_definitions.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #all ⇒ Object
- #defined ⇒ Object
- #each(&block) ⇒ Object
- #find(name) ⇒ Object
- #reset ⇒ Object
- #write(name, config:, records:, format: :file) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
17 18 19 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 17 def [](name) defined.fetch(name) end |
#all ⇒ Object
6 7 8 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 6 def all defined.values end |
#defined ⇒ Object
10 11 12 13 14 15 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 10 def defined @defined ||= yaml_files .map { |file| load_yml_zone_definition(file) } .sort_by(&:unrooted_name) .index_by(&:unrooted_name) end |
#each(&block) ⇒ Object
21 22 23 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 21 def each(&block) defined.each(&block) end |
#find(name) ⇒ Object
25 26 27 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 25 def find(name) defined[name] end |
#reset ⇒ Object
29 30 31 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 29 def reset @defined = nil end |
#write(name, config:, records:, format: :file) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/record_store/zone/yaml_definitions.rb', line 33 def write(name, config:, records:, format: :file) raise ArgumentError, "format must be :directory or :file" unless [:file, :directory].include?(format) name = name.chomp('.') zone_file = "#{RecordStore.zones_path}/#{name}.yml" zone = { name => { config: config.to_hash } } records = records.map(&:to_hash).sort_by! { |r| [r.fetch(:fqdn), r.fetch(:type), r[:nsdname] || r[:address]] } if format == :file zone[name][:records] = records write_yml_file(zone_file, zone.deep_stringify_keys) remove_record_files(name) else write_yml_file(zone_file, zone.deep_stringify_keys) remove_record_files(name) write_record_files(name, records) end end |