Module: Grifter::Configuration
- Included in:
- Grifter
- Defined in:
- lib/grifter/configuration.rb
Instance Method Summary collapse
- #load_config_file(options = {}) ⇒ Object
-
#normalize_config(config, options = {}) ⇒ Object
this method ensure the config hash has everything we need to instantiate the service objects.
- #recursive_symbolize(hash) ⇒ Object
Instance Method Details
#load_config_file(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grifter/configuration.rb', line 19 def load_config_file ={} = { config_file: ENV['GRIFTER_CONFIG_FILE'] ? ENV['GRIFTER_CONFIG_FILE'] : 'grifter.yml', environment: ENV['GRIFTER_ENVIRONMENT'], }.merge() Log.debug "Loading config file '#{[:config_file]}'" unless File.exist?([:config_file]) raise "No such config file: '#{[:config_file]}'" end hash = YAML.load_file([:config_file]) symbolized = recursive_symbolize(hash) normalize_config(symbolized, ) end |
#normalize_config(config, options = {}) ⇒ Object
this method ensure the config hash has everything we need to instantiate the service objects
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
# File 'lib/grifter/configuration.rb', line 34 def normalize_config config, ={} unless ((config.is_a? Hash) && (config.has_key? :services) && (config[:services].is_a? Hash) && (config[:services].length > 0)) raise GrifterConfigurationError.new ":services block not found in configuration" end #fill out services block entirely for each service config[:services].each_pair do |service_name, service_config| service_config[:name] = service_name.to_s #setup port config unless service_config[:port] if service_config[:ssl] service_config[:port] = 443 else service_config[:port] = 80 end end #ssl config unless service_config[:ssl] service_config[:ssl] = false end #ignore_ssl_certificate unless service_config[:ignore_ssl_cert] service_config[:ignore_ssl_cert] = false end unless service_config[:base_uri] service_config[:base_uri] = '' end end #merge any environment overrides into the service block if [:environment] [:environment] = [:environment].to_sym unless config[:environments] && config[:environments][[:environment]] raise GrifterConfigurationError.new "No such environment specified in config: '#{[:environment]}'" end config[:environments][[:environment]].each_pair do |service_name, service_overrides| config[:services][service_name].merge! service_overrides end end return config end |
#recursive_symbolize(hash) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/grifter/configuration.rb', line 7 def recursive_symbolize hash hash.inject({}) do |h, (k,v)| h[k.intern] = case v when Hash recursive_symbolize v else v end h end end |