Class: Flapjack::Configuration
- Inherits:
-
Object
- Object
- Flapjack::Configuration
- Defined in:
- lib/flapjack/configuration.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/flapjack/configuration.rb', line 9 def filename @filename end |
Instance Method Details
#all ⇒ Object
11 12 13 |
# File 'lib/flapjack/configuration.rb', line 11 def all @config end |
#for_redis ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flapjack/configuration.rb', line 15 def for_redis return unless @config redis_defaults = {'host' => '127.0.0.1', 'port' => 6379, 'path' => nil, 'db' => 0} @config['redis'] = {} unless @config.has_key?('redis') redis = @config['redis'] redis_defaults.each_pair do |k,v| next if redis.has_key?(k) && !redis[k].nil? && !(redis[k].is_a?(String) && redis[k].empty?) redis[k] = v end redis_path = (redis['path'] || nil) base_opts = HashWithIndifferentAccess.new({ :db => (redis['db'] || 0) }) base_opts[:driver] = redis['driver'] unless redis['driver'].nil? redis_config = base_opts.merge( (redis_path ? { :path => redis_path } : { :host => (redis['host'] || '127.0.0.1'), :port => (redis['port'] || 6379)}) ) redis_config[:password] = redis["password"] if redis["password"] redis_config end |
#load(file_pattern) ⇒ Object
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 85 86 87 88 89 |
# File 'lib/flapjack/configuration.rb', line 46 def load(file_pattern) @file_pattern = nil @config = nil config_file_names = Dir.glob(file_pattern) if config_file_names.nil? Flapjack.logger.error { "Could not load config files using file_pattern '#{file_pattern}'" } return end yaml_file = config_file_names.detect {|f| f.end_with?('.yaml') } unless yaml_file.nil? raise "#{yaml_file} looks like a YAML file. Flapjack v2 config files are now in TOML, " + "see flapjack.io/docs/2.x/configuration" end config = config_file_names.inject({}) do |config, file_name| config.merge!(TOML.load_file(file_name)) do |key, old_val, new_val| if old_val != new_val Flapjack.logger.error { "Duplicate configuration setting #{key} in #{file_name}" } break else new_val end end end if config.nil? || config.empty? Flapjack.logger.error { "Could not load config files using file_pattern '#{file_pattern}'" } return end @config = HashWithIndifferentAccess.new(config) @file_pattern = file_pattern end |
#reload ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/flapjack/configuration.rb', line 91 def reload if @file_pattern.nil? Flapjack.logger.error "Cannot reload, config file_pattern not set." return end load(@file_pattern) end |