module Zonify::Mappings
Public Instance Methods
apply(name, mappings)
click to toggle source
Apply mappings to the name in order. (A hash can be used for mappings but then one will not be able to predict the order.) If no mappings apply, the empty list is returned.
# File lib/zonify.rb, line 584 def apply(name, mappings) name_ = Zonify.dot_(name) mappings.map do |k, v| _k_ = Zonify.dot_(Zonify._dot(k)) before = Zonify::Mappings.unsuffix(name_, _k_) v.map{|s| Zonify.dot_(before + Zonify._dot(s)) } if before end.compact.flatten end
names(name, mappings)
click to toggle source
Get the names that result from the mappings, or the original name if none apply. The first name in the list is taken to be the canonical name, the one used for groups of servers in SRV records.
# File lib/zonify.rb, line 595 def names(name, mappings) mapped = Zonify::Mappings.apply(name, mappings) mapped.empty? ? [name] : mapped end
parse(s)
click to toggle source
# File lib/zonify.rb, line 577 def parse(s) k, *v = s.split(':') [k, v] if k and v and not v.empty? end
rewrite(tree, mappings)
click to toggle source
# File lib/zonify.rb, line 603 def rewrite(tree, mappings) tree.inject({}) do |acc, pair| name, info = pair names = Zonify::Mappings.names(name, mappings) names.each do |name| acc[name] ||= {} info.inject(acc[name]) do |acc_, pair_| type, data = pair_ acc_[type] ||= {} prefix_ = Zonify.dot_(Zonify::Resolve::SRV_PREFIX) rrs = if type == 'SRV' and name.start_with? prefix_ and data[:value] data[:value].map do |rr| if /^(.+) ([^ ]+)$/.match(rr) "#{$1} #{Zonify::Mappings.names($2, mappings).first}" else rr end end end normed = (rrs + (acc_[type][:value] or [])).sort.uniq if rrs addenda = normed ? { :value => normed } : {} acc_[type] = data.merge(addenda) acc_ end end acc end end
unsuffix(s, suffix)
click to toggle source
# File lib/zonify.rb, line 599 def unsuffix(s, suffix) before, _, after = s.rpartition(suffix) before if after.empty? end