lib/nurse/service_factory.rb in nurse-rb-2.0.0 vs lib/nurse/service_factory.rb in nurse-rb-2.1.0
- old
+ new
@@ -1,17 +1,49 @@
module Nurse
class ServiceFactory
def attach_to(dependency_manager)
+ if shared?
+ dependency_manager.share(dependency_key) do |di|
+ create_service(di)
+ end
+
+ return
+ end
+
dependency_manager.set(dependency_key) do |di|
create_service(di)
end
end
def create_service(_dependency_manager)
- fail 'create_service must be implemented'
+ raise 'create_service must be implemented'
end
def dependency_key
- fail 'dependency_key must be implemented'
+ raise 'dependency_key must be implemented'
+ end
+
+ def shared?
+ false
+ end
+
+ class << self
+ private
+
+ def share(boolean)
+ instance_eval do
+ define_method :shared? do
+ boolean
+ end
+ end
+ end
+
+ def key(dependency_key)
+ instance_eval do
+ define_method :dependency_key do
+ dependency_key
+ end
+ end
+ end
end
end
end