class URIConfig::Config
Constants
- FETCH_ERROR
Attributes
url[R]
Public Class Methods
config(*keys)
click to toggle source
# File lib/uri_config/config.rb, line 81 def self.config(*keys) define_method :config do keys. inject({}) do |hash, key| hash[key] = send(key) hash end. reject { |_, value| value.nil? } end end
configure_from(env_var, &block)
click to toggle source
# File lib/uri_config/config.rb, line 22 def self.configure_from(env_var, &block) configure_from!(env_var, &block) rescue FETCH_ERROR nil end
configure_from!(env_var) { |config| ... }
click to toggle source
# File lib/uri_config/config.rb, line 28 def self.configure_from!(env_var) config = new ENV.fetch(env_var) if block_given? yield config else config end end
map(key, options = {})
click to toggle source
# File lib/uri_config/config.rb, line 12 def self.map(key, options = {}) alias_method key, options.fetch(:from) end
new(url)
click to toggle source
# File lib/uri_config/config.rb, line 8 def initialize(url) @url = url end
parameter(method, query_parameter = method)
click to toggle source
# File lib/uri_config/config.rb, line 16 def self.parameter(method, query_parameter = method) define_method(method) do query[query_parameter.to_s].first end end
values_from(env_var, *params)
click to toggle source
# File lib/uri_config/config.rb, line 38 def self.values_from(env_var, *params) config = configure_from!(env_var) params.map { |param| config.send(param) } end
Public Instance Methods
==(other)
click to toggle source
# File lib/uri_config/config.rb, line 44 def ==(other) return false unless other.is_a?(self.class) url == other.url end
base_uri()
click to toggle source
# File lib/uri_config/config.rb, line 74 def base_uri uri.dup.tap do |uri| uri.user = nil uri.password = nil end.to_s end
host()
click to toggle source
# File lib/uri_config/config.rb, line 58 def host uri.host end
password()
click to toggle source
# File lib/uri_config/config.rb, line 54 def password CGI.unescape uri.password if uri.password end
path()
click to toggle source
# File lib/uri_config/config.rb, line 66 def path uri.path end
port()
click to toggle source
# File lib/uri_config/config.rb, line 62 def port uri.port end
scheme()
click to toggle source
# File lib/uri_config/config.rb, line 70 def scheme uri.scheme end
username()
click to toggle source
# File lib/uri_config/config.rb, line 50 def username CGI.unescape uri.user if uri.user end
Private Instance Methods
query()
click to toggle source
# File lib/uri_config/config.rb, line 98 def query CGI.parse(uri.query || '') end
uri()
click to toggle source
# File lib/uri_config/config.rb, line 102 def uri @uri ||= URI.parse url rescue URI::InvalidURIError raise URI::InvalidURIError, "Invalid URI: <URL_SUPPRESSED>" end