class Resty::Options
Constants
- CONFIG_FILE
Attributes
options[R]
Public Class Methods
build_pair(header)
click to toggle source
# File lib/resty/options.rb, line 47 def self.build_pair(header) split_headers = header.split(":") { split_headers.shift.to_sym => split_headers.join(":") } end
new(options)
click to toggle source
# File lib/resty/options.rb, line 9 def initialize(options) @options = options if options[:headers] options[:headers] = Options.parse_headers(options[:headers]) elsif host_alias load_config_file end end
parse_headers(headers)
click to toggle source
# File lib/resty/options.rb, line 43 def self.parse_headers(headers) headers.inject({}) { |hash, header| hash.merge(build_pair(header)) } end
Public Instance Methods
headers()
click to toggle source
# File lib/resty/options.rb, line 31 def headers options[:headers] || {} end
host()
click to toggle source
# File lib/resty/options.rb, line 19 def host options[:host] end
host_alias()
click to toggle source
# File lib/resty/options.rb, line 27 def host_alias options[:alias] end
password()
click to toggle source
# File lib/resty/options.rb, line 39 def password options[:password] end
username()
click to toggle source
# File lib/resty/options.rb, line 35 def username options[:username] end
verbose?()
click to toggle source
# File lib/resty/options.rb, line 23 def verbose? options[:verbose] ? true : false end
Private Instance Methods
load_config_file()
click to toggle source
# File lib/resty/options.rb, line 54 def load_config_file read_config_file.tap do |config| options[:host] = config[host_alias]["host"] options[:headers] = config[host_alias]["headers"] options[:username] = config[host_alias]["username"] options[:password] = config[host_alias]["password"] end end
read_config_file()
click to toggle source
# File lib/resty/options.rb, line 63 def read_config_file if File.exist?(CONFIG_FILE) YAML.load_file(CONFIG_FILE).tap { |config| validate_config_entries(config) } else raise ConfigFileError, "#{CONFIG_FILE} is missing." end end
validate_config_entries(config)
click to toggle source
# File lib/resty/options.rb, line 71 def validate_config_entries(config) if config[host_alias] unless config[host_alias]["host"] raise ConfigFileError, "Host missing from #{CONFIG_FILE}" end else raise ConfigFileError, "Alias missing from #{CONFIG_FILE}: #{host_alias}" end end