module Hatt::Configuration
Constants
- DEFAULT_CONFIG_FILE
- DEFAULT_HATT_GLOBS
Public Instance Methods
hatt_config_file=(filename)
click to toggle source
# File lib/hatt/configuration.rb, line 15 def hatt_config_file=(filename) @hatt_config_file = filename init_config self end
Also aliased as: hatt_config_file
hatt_configuration()
click to toggle source
# File lib/hatt/configuration.rb, line 10 def hatt_configuration init_config @hatt_configuration.tcfg end
Private Instance Methods
hatt_config_file_path()
click to toggle source
# File lib/hatt/configuration.rb, line 24 def hatt_config_file_path if instance_variable_defined? :@hatt_config_file and not @hatt_config_file.nil? File.expand_path @hatt_config_file elsif File.exist? DEFAULT_CONFIG_FILE File.expand_path DEFAULT_CONFIG_FILE else nil end end
init_config()
click to toggle source
ensure the configuration is resolved and ready to use
# File lib/hatt/configuration.rb, line 35 def init_config unless instance_variable_defined? :@hatt_configuration @hatt_configuration = TCFG::Base.new # build up some default configuration @hatt_configuration.tcfg_set 'hatt_services', {} @hatt_configuration.tcfg_set 'hatt_globs', DEFAULT_HATT_GLOBS @hatt_configuration.tcfg_set_env_var_prefix 'HATT_' end if hatt_config_file_path # if a config file was specified, we assume it exists @hatt_configuration.tcfg_config_file hatt_config_file_path else Log.warn 'No configuration file specified or found. Make a hatt.yml file and point hatt at it.' end @hatt_configuration.tcfg_set 'hatt_config_file', hatt_config_file_path normalize_services_config @hatt_configuration nil end
normalize_services_config(cfg)
click to toggle source
# File lib/hatt/configuration.rb, line 59 def normalize_services_config(cfg) services = cfg['hatt_services'] services.each_pair do |svc, svc_cfg| # add the name svc_cfg['name'] = svc unless svc_cfg.key? :url raise ConfigurationError, "url for service '#{svc_cfg['name']}' is not defined" end unless svc_cfg['url'] =~ URI::ABS_URI raise ConfigurationError, "url for service '#{svc_cfg['name']}' is not a proper absolute URL: #{svc_cfg['url']}" end parsed = URI.parse svc_cfg['url'] svc_cfg['base_uri'] ||= parsed.path svc_cfg['faraday_url'] = "#{parsed.scheme}://#{parsed.host}:#{parsed.port}" end cfg.tcfg_set 'hatt_services', services end