10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/pathsconfig/base.rb', line 10
def path_array(path_name)
raise Pathsconfig::ConfigError, "Pathsconfig has not been configured." unless Pathsconfig.config
raise Pathsconfig::ModelError, "class '#{self.class.name}' does not respond to the 'path_config' method." unless self.class.respond_to?(:path_config)
path_value = Pathsconfig.config[self.class.path_config.to_sym][path_name.to_sym]
if path_value.kind_of?(Hash)
raise Pathsconfig::ModelError, "multiple path types are configured and this model does not respond to the 'path_type' method." unless self.respond_to?(:path_type)
raise Pathsconfig::ModelError, "an '#{self.path_type}' type of the '#{path_name}' path has not been configured" if path_value[self.path_type.to_sym].nil?
path_value[self.path_type.to_sym].collect{ |exp| eval(exp) }.flatten
elsif path_value.kind_of?(Array)
path_value.collect{ |exp| eval(exp) }.flatten
elsif path_value.nil? || path_value.empty?
raise Pathsconfig::ModelError, "'#{path_name}' is not configured for #{self.class.name}"
else
raise Pathsconfig::ModelError, "'#{path_name}' is incorrectly configured for #{self.class.name}"
end
end
|