repl.it
@adam121/

BraveEducatedMatch

Ruby

No description

fork
loading
Files
  • main.rb
  • postgres_adapter.rb
  • sqlite_adapter.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module MyApp
  def self.adapter_registry
    @adapter_registry ||= {}
  end

  def self.adapter_for(adapter_name)
    adapter_registry.fetch(adapter_name) {
      require_relative "#{adapter_name}_adapter"

      adapter_klass = Adapters.const_get(adapter_name.capitalize)
      adapter = adapter_klass.new

      adapter_registry[adapter_name] = adapter
      adapter
    }
  end
end

sqlite_adapter = MyApp.adapter_for(:sqlite)
postgres_adapter = MyApp.adapter_for(:postgres)
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
?