Class: Unbind::View

Inherits:
Object
  • Object
show all
Defined in:
lib/unbind/view.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ View

Returns a new instance of View.



13
14
15
16
17
18
19
20
21
# File 'lib/unbind/view.rb', line 13

def initialize name, config
  raise "view must have a name" unless name.is_a?(String) && 0 < name.length
  raise "config should include clients and zones lists" unless
    config.is_a?(Hash) && [:clients, :zones].all? { |k| config.has_key?(k) && config[k].is_a?(Array) }

  @name = name
  @clients = config[:clients]
  @zones = config[:zones]
end

Class Method Details

.expand_countries(clients) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/unbind/view.rb', line 3

def self.expand_countries clients
  clients.flat_map { |i|
    if i.is_a?(Hash) && i.has_key?("countries")
      i["countries"].map { |c| "country_#{c.upcase}" }
    else
      i
    end
  }
end

Instance Method Details

#clientsObject



31
32
33
# File 'lib/unbind/view.rb', line 31

def clients
  self.class.expand_countries(@clients)
end

#masterObject



27
28
29
# File 'lib/unbind/view.rb', line 27

def master
  ["view \"#{@name}\" {", match_clients, servers, view_settings(:master), zones(:master), "};\n"].join("\n")
end

#slaveObject



23
24
25
# File 'lib/unbind/view.rb', line 23

def slave
  ["view \"#{@name}\" {", match_clients, zones(:slave), "};\n"].join("\n")
end