Sha256: 4d3d116ca10401ba3aa5349d64ead65608779fdcdb1859a65181271c2242396e

Contents?: true

Size: 944 Bytes

Versions: 14

Compression:

Stored size: 944 Bytes

Contents

module Railjet
  module Repository
    attr_reader :registry
    delegate    :settings, to: :registry

    def initialize(registry, **kwargs)
      @registry = registry
      initialize_specific_repositories(**kwargs)
    end

    private

    def repositories
      klass         = self.class
      inner_klasses = klass.constants
      inner_repos   = inner_klasses.select { |k| k.to_s.end_with?("Repository") }
      
      inner_repos.map do |k|
        klass.const_get(k)
      end
    end

    def initialize_specific_repositories(**kwargs)
      repositories.each do |repo|
        initialize_repository(repo, **kwargs)
      end
    end

    private

    def initialize_repository(repository, **kwargs)
      ivar = "@#{repository.type}"
      dao  = kwargs[repository.type]

      instance_variable_set(ivar, repository.new(registry, :"#{repository.type}" => dao))
      self.class.send :attr_reader, repository.type
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
railjet-4.0.0 lib/railjet/repository.rb
railjet-3.5.0 lib/railjet/repository.rb
railjet-3.4.0 lib/railjet/repository.rb
railjet-3.3.0 lib/railjet/repository.rb
railjet-3.2.0 lib/railjet/repository.rb
railjet-3.1.0 lib/railjet/repository.rb
railjet-3.0.0 lib/railjet/repository.rb
railjet-2.1.1 lib/railjet/repository.rb
railjet-2.1 lib/railjet/repository.rb
railjet-2.0 lib/railjet/repository.rb
railjet-2.0.pre4 lib/railjet/repository.rb
railjet-2.0.pre3 lib/railjet/repository.rb
railjet-2.0.pre2 lib/railjet/repository.rb
railjet-2.0.pre1 lib/railjet/repository.rb