@@ -73,29 +73,37 @@ def dispatchers_options
73
73
. map { |options | options . dup . symbolize_keys }
74
74
end
75
75
76
+
76
77
def load_config_from ( file_or_hash )
77
78
case file_or_hash
78
- when Pathname then load_config_file file_or_hash
79
- when String then load_config_file Pathname . new ( file_or_hash )
80
- when NilClass then load_config_file default_config_file
81
- when Hash then file_or_hash . dup
82
- else raise "Solid Queue cannot be initialized with #{ file_or_hash . inspect } "
79
+ when Hash
80
+ file_or_hash . dup
81
+ when Pathname , String
82
+ load_config_from_file Pathname . new ( file_or_hash )
83
+ when NilClass
84
+ load_config_from_env_location || load_config_from_default_location
85
+ else
86
+ raise "Solid Queue cannot be initialized with #{ file_or_hash . inspect } "
83
87
end
84
88
end
85
89
86
- def load_config_file ( file )
87
- if file . exist?
88
- ActiveSupport ::ConfigurationFile . parse ( file ) . deep_symbolize_keys
89
- else
90
- raise "Configuration file not found in #{ file } "
90
+ def load_config_from_env_location
91
+ if ENV [ "SOLID_QUEUE_CONFIG" ] . present?
92
+ load_config_from_file Rails . root . join ( ENV [ "SOLID_QUEUE_CONFIG" ] )
91
93
end
92
94
end
93
95
94
- def default_config_file
95
- path_to_file = ENV [ "SOLID_QUEUE_CONFIG" ] || DEFAULT_CONFIG_FILE_PATH
96
+ def load_config_from_default_location
97
+ Rails . root . join ( DEFAULT_CONFIG_FILE_PATH ) . then do |config_file |
98
+ config_file . exist? ? load_config_from_file ( config_file ) : { }
99
+ end
100
+ end
96
101
97
- Rails . root . join ( path_to_file ) . tap do |config_file |
98
- raise "Configuration for Solid Queue not found in #{ config_file } " unless config_file . exist?
102
+ def load_config_from_file ( file )
103
+ if file . exist?
104
+ ActiveSupport ::ConfigurationFile . parse ( file ) . deep_symbolize_keys
105
+ else
106
+ raise "Configuration file for Solid Queue not found in #{ file } "
99
107
end
100
108
end
101
109
end
0 commit comments