Class: Servel::ConfigParser
- Inherits:
-
Object
- Object
- Servel::ConfigParser
- Defined in:
- lib/servel/config_parser.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ ConfigParser
constructor
A new instance of ConfigParser.
- #parse_argv ⇒ Object
- #parse_binds ⇒ Object
- #parse_ssl_bind ⇒ Object
Constructor Details
#initialize ⇒ ConfigParser
Returns a new instance of ConfigParser.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/servel/config_parser.rb', line 4 def initialize @tty_config = TTY::Config.new @tty_config.filename = "servel" @tty_config.append_path(Dir.pwd) @tty_config.append_path((Pathname.new(Dir.home) + ".servel").to_s) @tty_config.append_path(Dir.home) @tty_config.env_prefix = "servel" @tty_config.autoload_env @tty_config.read if @tty_config.exist? @tty_config.append(*parse_argv, to: :listings) parse_binds @config = @tty_config.to_h.transform_keys(&:to_sym) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2 3 4 |
# File 'lib/servel/config_parser.rb', line 2 def config @config end |
Instance Method Details
#parse_argv ⇒ Object
20 21 22 23 24 25 |
# File 'lib/servel/config_parser.rb', line 20 def parse_argv ARGV.map do |arg| root, url_root = arg.split(":" , 2) { root => url_root } end end |
#parse_binds ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/servel/config_parser.rb', line 27 def parse_binds return parse_ssl_bind if @tty_config.fetch(:cert) && @tty_config.fetch(:key) host = @tty_config.fetch(:host) port = @tty_config.fetch(:port) @tty_config.set(:Host, value: host) if host @tty_config.set(:Port, value: port) if port end |
#parse_ssl_bind ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/servel/config_parser.rb', line 36 def parse_ssl_bind host = @tty_config.fetch(:host, default: ::Puma::ConfigDefault::DefaultTCPHost) port = @tty_config.fetch(:port, default: ::Puma::ConfigDefault::DefaultTCPPort) key = Pathname.new(@tty_config.fetch(:key)). cert = Pathname.new(@tty_config.fetch(:cert)). query = URI.encode_www_form(key: key, cert: cert) @tty_config.append("ssl://#{host}:#{port}?#{query}", to: :binds) end |