class Resque::Pool::ConfigLoaders::FileOrHashLoader
Constants
- CONFIG_FILES
Public Class Methods
new(filename_or_hash=nil)
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 6 def initialize(filename_or_hash=nil) case filename_or_hash when String, nil @filename = filename_or_hash when Hash @static_config = filename_or_hash.dup else raise "#{self.class} cannot be initialized with #{filename_or_hash.inspect}" end end
Public Instance Methods
call(environment)
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 17 def call(environment) @config ||= load_config_from_file(environment) end
reset!()
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 21 def reset! @config = nil end
Private Instance Methods
apply_environment(config, environment)
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 37 def apply_environment(config, environment) environment and config[environment] and config.merge!(config[environment]) config.delete_if {|key, value| value.is_a? Hash } end
choose_config_file()
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 52 def choose_config_file if ENV["RESQUE_POOL_CONFIG"] ENV["RESQUE_POOL_CONFIG"] else CONFIG_FILES.detect { |f| File.exist?(f) } end end
config_filename()
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 42 def config_filename @filename || choose_config_file end
load_config(filename)
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 46 def load_config(filename) return {} unless filename YAML.load(ERB.new(IO.read(filename)).result) end
load_config_from_file(environment)
click to toggle source
# File lib/resque/pool/config_loaders/file_or_hash_loader.rb, line 27 def load_config_from_file(environment) if @static_config new_config = @static_config else filename = config_filename new_config = load_config filename end apply_environment new_config, environment end