Class: Vines::Agent::Config::Domain
- Inherits:
-
Object
- Object
- Vines::Agent::Config::Domain
- Defined in:
- lib/vines/agent/config.rb
Instance Method Summary collapse
- #download(dir) ⇒ Object
-
#initialize(name, &block) ⇒ Domain
constructor
A new instance of Domain.
- #password(password = nil) ⇒ Object
- #start ⇒ Object
- #upstream(host, port) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Domain
Returns a new instance of Domain.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vines/agent/config.rb', line 51 def initialize(name, &block) @name, @password, @upstream = name, nil, [] @conf = File.('conf') instance_eval(&block) if block validate_domain(@name) raise "password required" unless @password && !@password.strip.empty? raise "duplicate upstream connections not allowed" if @upstream.uniq! unless @download @download = File.('data') FileUtils.mkdir_p(@download) end end |
Instance Method Details
#download(dir) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/vines/agent/config.rb', line 72 def download(dir) @download = File.(dir) begin FileUtils.mkdir_p(@download) rescue raise "can't create #{@download}" end end |
#password(password = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/vines/agent/config.rb', line 64 def password(password=nil) if password @password = password else @password end end |
#start ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vines/agent/config.rb', line 86 def start base = { password: @password, domain: @name, download: @download, conf: @conf } = @upstream.map do |info| base.clone.tap do |opts| opts[:host] = info[:host] opts[:port] = info[:port] end end # no upstream so use DNS SRV discovery for host and port << base if .empty? .each do |args| Vines::Agent::Connection.new(args).start end end |
#upstream(host, port) ⇒ Object
81 82 83 84 |
# File 'lib/vines/agent/config.rb', line 81 def upstream(host, port) raise 'host and port required for upstream connections' unless host && port @upstream << {host: host, port: port} end |