Module: Unbind
- Defined in:
- lib/unbind.rb,
lib/unbind/view.rb,
lib/unbind/zone.rb,
lib/unbind/version.rb
Defined Under Namespace
Constant Summary collapse
- Commands =
%w(master slave zone).freeze
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.geoip ⇒ Object
readonly
Returns the value of attribute geoip.
Class Method Summary collapse
- .clear_config ⇒ Object
- .init_geoip ⇒ Object
- .load_config(config) ⇒ Object
-
.load_file(f) ⇒ Object
private.
- .load_string(s) ⇒ Object
- .master ⇒ Object
- .policies ⇒ Object
- .prepare_config ⇒ Object
- .slave ⇒ Object
- .symbolize_config ⇒ Object
- .views ⇒ Object
- .zone(zone_names) ⇒ Object
- .zones ⇒ Object
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/unbind.rb', line 16 def config @config end |
.geoip ⇒ Object (readonly)
Returns the value of attribute geoip.
16 17 18 |
# File 'lib/unbind.rb', line 16 def geoip @geoip end |
Class Method Details
.clear_config ⇒ Object
54 55 56 |
# File 'lib/unbind.rb', line 54 def clear_config @config = {} end |
.init_geoip ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/unbind.rb', line 63 def init_geoip if @config[:geoip_dat] begin require 'geoip' @geoip = GeoIP.new(@config[:geoip_dat]) rescue LoadError end end end |
.load_config(config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/unbind.rb', line 18 def load_config config clear_config files = File.directory?(config) ? Dir["#{config}/**/*.conf"] : Dir[config] raise "No files could be found (search path: #{config})" if files.empty? files.each { |f| raise "File '#{f}' could not be loaded" unless load_file(f) } prepare_config true end |
.load_file(f) ⇒ Object
private
44 45 46 |
# File 'lib/unbind.rb', line 44 def load_file f load_string(File.read(File.(f))) end |
.load_string(s) ⇒ Object
48 49 50 51 52 |
# File 'lib/unbind.rb', line 48 def load_string s data = YAML.load(s) raise "config data should be a hash" unless data.is_a? Hash @config.merge!(data) and true end |
.master ⇒ Object
30 31 32 |
# File 'lib/unbind.rb', line 30 def master(*) views.map { |v| v.master }.join("\n") end |
.policies ⇒ Object
85 86 87 88 89 |
# File 'lib/unbind.rb', line 85 def policies @policies ||= @config[:zones].reduce([]) { |a, (name, config)| a + (config[:policies] || []) }.map { |policy_name| Unbind::Policy.const_get(policy_name.camelize) } end |
.prepare_config ⇒ Object
58 59 60 61 |
# File 'lib/unbind.rb', line 58 def prepare_config symbolize_config init_geoip end |
.slave ⇒ Object
34 35 36 |
# File 'lib/unbind.rb', line 34 def slave(*) views.map { |v| v.slave }.join("\n") end |
.symbolize_config ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/unbind.rb', line 73 def symbolize_config @config.symbolize_keys! @config[:views] ||= {} @config[:zones] ||= {} @config[:zones].each do |k, v| v.symbolize_keys! v[:data].symbolize_keys! end end |
.views ⇒ Object
95 96 97 |
# File 'lib/unbind.rb', line 95 def views @views ||= @config[:views].map { |name, clients| Unbind::View.new(name, {clients: clients, zones: zones}) } end |