app/models/service_store.rb in umlaut-4.0.3 vs app/models/service_store.rb in umlaut-4.1.0.pre.alpha.1
- old
+ new
@@ -31,16 +31,23 @@
global_service_store.send(method, *args)
end
end
- # Returns complete hash loaded from services.yml
+ # Returns complete hash loaded from config/umlaut_services.yml
+ # Passes through ERB first, allowing ERB in umlaut_services.yml
def config
# cache hash loaded from YAML, ensure it has the keys we expect.
unless defined? @services_config_list
yaml_path = File.expand_path("config/umlaut_services.yml", Rails.root)
- @services_config_list = (File.exists? yaml_path) ? YAML::load(File.open(yaml_path)) : {}
+
+ @services_config_list = if File.exists? yaml_path
+ YAML::load(ERB.new(File.open(yaml_path).read).result)
+ else
+ {}
+ end
+
@services_config_list["default"] ||= {}
@services_config_list["default"]["services"] ||= {}
end
return @services_config_list
end
@@ -118,15 +125,21 @@
# pass in string unique key OR a service definition hash,
# and a current UmlautRequest.
# get back instantiated Service object.
+ #
+ # If string service_id is passed in, but is not defined in application services,
+ # a ServiceStore::NoSuchService exception will be raised.
def instantiate_service!(service, request)
definition = service.kind_of?(Hash) ? service : service_definition_for(service.to_s)
- raise "Service '#{service}'' does not exist in umlaut-services.yml" if definition.nil?
+ raise NoSuchService.new("Service '#{service}'' does not exist in umlaut-services.yml") if definition.nil?
className = definition["type"] || definition["service_id"]
classConst = Kernel.const_get(className)
service = classConst.new(definition)
service.request = request
return service
end
+
+ class NoSuchService < RuntimeError ; end
+
end