Sha256: 81007fc11240c8f3b205c5254d813897b91a24e2ccee53ffd8dbd4f84d0880ba

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

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)
      raise 'create_service must be implemented'
    end

    def dependency_key
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nurse-rb-2.1.0 lib/nurse/service_factory.rb