Class: Envoy::Client::Config
- Inherits:
-
Object
- Object
- Envoy::Client::Config
- Defined in:
- lib/envoy/client/config.rb,
lib/envoy/client/config/builder.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#export ⇒ Object
Returns the value of attribute export.
-
#key ⇒ Object
Returns the value of attribute key.
-
#label ⇒ Object
Returns the value of attribute label.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #infer_sane_defaults ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #options ⇒ Object
- #parse_envoyfile ⇒ Object
- #parse_options ⇒ Object
- #start_service ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 |
# File 'lib/envoy/client/config.rb', line 13 def initialize @server = ["p45.eu", 8282] @key = ENV["ENVOY_KEY"] || SecureRandom.base64(8) end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
10 11 12 |
# File 'lib/envoy/client/config.rb', line 10 def command @command end |
#export ⇒ Object
Returns the value of attribute export.
11 12 13 |
# File 'lib/envoy/client/config.rb', line 11 def export @export end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/envoy/client/config.rb', line 8 def key @key end |
#label ⇒ Object
Returns the value of attribute label.
9 10 11 |
# File 'lib/envoy/client/config.rb', line 9 def label @label end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/envoy/client/config.rb', line 7 def server @server end |
Instance Method Details
#infer_sane_defaults ⇒ Object
39 40 41 |
# File 'lib/envoy/client/config.rb', line 39 def infer_sane_defaults self.export = [:tcp, "127.0.0.1", 80] unless export end |
#options ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/envoy/client/config.rb', line 18 def { hosts: [label].compact, key: key, verbosity: true, version: Envoy::VERSION } end |
#parse_envoyfile ⇒ Object
43 44 45 46 47 |
# File 'lib/envoy/client/config.rb', line 43 def parse_envoyfile if path = Envoy.find_file("Envoyfile") Builder.new(self).run(path) end end |
#parse_options ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/envoy/client/config.rb', line 49 def OptionParser.new do |op| op. = "Usage: #{$0} [options]" op.on "-l LABEL", "Use this domain label" do |lab| @label = lab end op.on "-d DIRECTORY", "Change to this directory before starting envoy" do |dir| Dir.chdir(dir) end op.on "-k KEY", "Secure access to the label with this key" do |v| @key = v end op.on "-s SERVER", "Specify envoy server" do |v| host, port = v.split(":") @server = [host, port || @server[1]] end op.on "-v", "Show messages. Repeat to show more." do Envoy.verbosity += 1 end op.on "-q", "Hide messages. Repeat to hide more." do Envoy.verbosity -= 1 end op.on "-h", "Show this message" do puts op exit end op.on "-V", "Show version number" do puts Envoy::VERSION exit end op.parse! case ARGV[0] when nil when /\// @export = [:unix, ARGV[0]] when /^([^:]+):(\d+)$/ @export = [:tcp, $1 || "127.0.0.1", $2] when /^(\d+)$/ @export = [:tcp, "127.0.0.1", $1] else @export = [:tcp, ARGV[0], 80] end end end |
#start_service ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/envoy/client/config.rb', line 27 def start_service return unless command Envoy.log Envoy::INFO, "Starting service..." fork do ENV.delete("GEM_HOME") ENV.delete("GEM_PATH") ENV.delete("BUNDLE_BIN_PATH") ENV.delete("BUNDLE_GEMFILE") system(command) end end |