resque-pool 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +0,0 @@
1
- class FileOrHashLoader
2
- def initialize(filename_or_hash=nil)
3
- case filename_or_hash
4
- when String, nil
5
- @filename = filename_or_hash
6
- when Hash
7
- @static_config = filename_or_hash.dup
8
- else
9
- raise "#{self.class} cannot be initialized with #{filename_or_hash.inspect}"
10
- end
11
- end
12
-
13
- def call(environment)
14
- @config ||= load_config_from_file(environment)
15
- end
16
-
17
- def reset!
18
- @config = nil
19
- end
20
-
21
- private
22
-
23
- def load_config_from_file(environment)
24
- if @static_config
25
- new_config = @static_config
26
- else
27
- filename = config_filename
28
- new_config = load_config filename
29
- end
30
- apply_environment new_config, environment
31
- end
32
-
33
- def apply_environment(config, environment)
34
- environment and config[environment] and config.merge!(config[environment])
35
- config.delete_if {|key, value| value.is_a? Hash }
36
- end
37
-
38
- def config_filename
39
- @filename || choose_config_file
40
- end
41
-
42
- def load_config(filename)
43
- return {} unless filename
44
- YAML.load(ERB.new(IO.read(filename)).result)
45
- end
46
-
47
- CONFIG_FILES = ["resque-pool.yml", "config/resque-pool.yml"]
48
- def choose_config_file
49
- if ENV["RESQUE_POOL_CONFIG"]
50
- ENV["RESQUE_POOL_CONFIG"]
51
- else
52
- CONFIG_FILES.detect { |f| File.exist?(f) }
53
- end
54
- end
55
- end