Sha256: 425451a4c8a3cfc35b7bfd369eb158452ea3bd2dc3d4cb8e0e65aa6cc269c310

Contents?: true

Size: 733 Bytes

Versions: 23

Compression:

Stored size: 733 Bytes

Contents

module Rasti
  class App
    class ServiceFactory

      class << self

        def service(name, service_class=nil)
          services[name] = service_class || Consty.get(Inflecto.camelize(name), self)

          define_method name do
            cache[name] ||= begin
              adapter_class = Consty.get(settings[name][:adapter], self.class.services[name])
              self.class.services[name].new adapter_class.new(settings[name][:options])
            end
          end
        end

        def services
          @services ||= {}
        end

      end

      def initialize(settings)
        @settings = settings
        @cache = {}
      end

      private

      attr_reader :settings, :cache
      
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rasti-app-0.0.3 lib/rasti/app/service_factory.rb
rasti-app-0.0.2 lib/rasti/app/service_factory.rb
rasti-app-0.0.1 lib/rasti/app/service_factory.rb