Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

normalizing settings to avoid configuration errors

  • Loading branch information...
commit 47f918a88a58f699a899e66b94069751127fb000 1 parent 5db16d4
@kawamanza kawamanza authored
Showing with 23 additions and 5 deletions.
  1. +23 −5 lib/purgeable/settings.rb
View
28 lib/purgeable/settings.rb
@@ -6,14 +6,32 @@
module Purgeable
SETTINGS = {}.extend ::Methodize
- def self.load_settings file_path, env
+ def self.load_settings(file_path, env)
raise "Invalid config location: #{file_path.inspect}" unless File.exists? file_path
config = YAML.load(ERB.new(File.read(file_path)).result)[env]
SETTINGS.merge! config if config.is_a?(Hash)
- if defined? ::MethodizedHash
- SETTINGS.http_cache.each do |cfg|
- cfg.extend ::Methodize unless cfg.kind_of?(MethodizedHash)
- end
+ normalize_settings
+ end
+
+ private
+
+ def self.normalize_settings
+ SETTINGS["http_cache"] = [] unless SETTINGS.http_cache.is_a?(Array)
+ SETTINGS.http_cache.each do |cfg|
+ next unless cfg.is_a?(Hash)
+ cfg.extend ::Methodize if defined?(::MethodizedHash) && !cfg.kind_of?(MethodizedHash)
+ cfg["cache_locations"] =
+ case cfg["cache_locations"]
+ when String then [cfg["cache_locations"]]
+ when Array then cfg["cache_locations"]
+ else []
+ end
+ cfg["resource_hosts"] =
+ case cfg["resource_hosts"]
+ when String then [cfg["resource_hosts"]]
+ when Array then cfg["resource_hosts"]
+ else []
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.