Class: Hosum::Hosts
Instance Attribute Summary collapse
-
#domains ⇒ Object
Returns the value of attribute domains.
Attributes inherited from Container
#children, #ips_list, #options, #parent
Instance Method Summary collapse
- #expand_domains ⇒ Object
-
#initialize ⇒ Hosts
constructor
A new instance of Hosts.
- #to_dnsmasq(options = {}) ⇒ Object
- #to_hosts(options = {}) ⇒ Object
Methods inherited from Container
Constructor Details
#initialize ⇒ Hosts
Returns a new instance of Hosts.
5 6 7 8 |
# File 'lib/hosum/hosts.rb', line 5 def initialize super self.domains = [] end |
Instance Attribute Details
#domains ⇒ Object
Returns the value of attribute domains.
3 4 5 |
# File 'lib/hosum/hosts.rb', line 3 def domains @domains end |
Instance Method Details
#expand_domains ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hosum/hosts.rb', line 10 def self.domains.map do |domain| holders = [] regex = /\[([^\[\]]+)-([^\[\]]+)\]/ domain = domain.gsub(regex) do |str| m = str.match(regex) holders << Range.new(m[1], m[2]).to_a "%s" end = [] holders.each do |holder| if .empty? = holder.map {|v| [v] } next end tmp = [] .each do || holder.each do |h| tmp << + [ h ] end end = tmp end if holders.empty? domain else .map { |e| domain % e} end end.flatten end |
#to_dnsmasq(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/hosum/hosts.rb', line 50 def to_dnsmasq( = {}) domains = self. if self.[:dnsmasq] domains = [ self.[:dnsmasq] ].flatten end domains.map{ |domain| "address=/#{domain}/#{find_first_ip}\n" }.join end |
#to_hosts(options = {}) ⇒ Object
46 47 48 |
# File 'lib/hosum/hosts.rb', line 46 def to_hosts( = {}) self..map{ |domain| "#{find_first_ip} #{domain}\n" }.join end |