Sha256: aea53f416f88d933b10fae58f4da3b3bd3b5e2706481d0f0585e89ef20add0b4

Contents?: true

Size: 896 Bytes

Versions: 9

Compression:

Stored size: 896 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
              raise "Undefined settings for service: #{name}" unless settings.key? name
              adapter_class = Consty.get(settings[name][:adapter], self.class.services[name])
              self.class.services[name].new adapter_class.new(environment, settings[name][:options])
            end
          end
        end

        def services
          @services ||= {}
        end

      end

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

      private

      attr_reader :environment, :settings, :cache
      
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rasti-app-11.0.0 lib/rasti/app/service_factory.rb
rasti-app-10.0.1 lib/rasti/app/service_factory.rb
rasti-app-10.0.0 lib/rasti/app/service_factory.rb
rasti-app-9.0.0 lib/rasti/app/service_factory.rb
rasti-app-8.0.1 lib/rasti/app/service_factory.rb
rasti-app-8.0.0 lib/rasti/app/service_factory.rb
rasti-app-7.1.1 lib/rasti/app/service_factory.rb
rasti-app-7.1.0 lib/rasti/app/service_factory.rb
rasti-app-7.0.2 lib/rasti/app/service_factory.rb