Class: Envoy::Client::Config::Builder
- Inherits:
-
Object
- Object
- Envoy::Client::Config::Builder
- Defined in:
- lib/envoy/client/config/builder.rb
Instance Method Summary collapse
- #export(type, *args) ⇒ Object
- #fetch(name, &block) ⇒ Object
-
#initialize(config) ⇒ Builder
constructor
A new instance of Builder.
- #localhost ⇒ Object
- #localport ⇒ Object
- #localsock ⇒ Object
- #run(path) ⇒ Object
- #set(name, value) ⇒ Object
Constructor Details
#initialize(config) ⇒ Builder
Returns a new instance of Builder.
5 6 7 |
# File 'lib/envoy/client/config/builder.rb', line 5 def initialize (config) @config = config end |
Instance Method Details
#export(type, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/envoy/client/config/builder.rb', line 25 def export (type, *args) case type when :tcp args = args[0].split(":") if args[0] and !args[1] args[0] ||= "127.0.0.1" args[1] ||= rand(16383) + 49152 args = [:tcp, *args] when :unix args[0] ||= ".envoy.sock" args = [:unix, *args] end set :export, args end |
#fetch(name, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/envoy/client/config/builder.rb', line 17 def fetch (name, &block) if r = @config.__send__(name) r elsif block set(name, block.()) end end |
#localhost ⇒ Object
43 44 45 |
# File 'lib/envoy/client/config/builder.rb', line 43 def localhost export(:tcp)[1] end |
#localport ⇒ Object
47 48 49 |
# File 'lib/envoy/client/config/builder.rb', line 47 def localport () export(:tcp)[2] end |
#localsock ⇒ Object
39 40 41 |
# File 'lib/envoy/client/config/builder.rb', line 39 def localsock () export(:unix)[1] end |
#run(path) ⇒ Object
9 10 11 |
# File 'lib/envoy/client/config/builder.rb', line 9 def run (path) instance_eval(File.read(path), path) end |
#set(name, value) ⇒ Object
13 14 15 |
# File 'lib/envoy/client/config/builder.rb', line 13 def set (name, value) @config.__send__("#{name}=", value) end |