Class: Kuby::Plugins::RailsApp::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/plugins/rails_app/database.rb

Constant Summary collapse

ADAPTER_MAP =

only support cockroach for now

{ cockroachdb: CRDB::Plugin, sqlite3: Sqlite }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rails_app) ⇒ Database

Returns a new instance of Database.



29
30
31
# File 'lib/kuby/plugins/rails_app/database.rb', line 29

def initialize(rails_app)
  @rails_app = rails_app
end

Instance Attribute Details

#rails_appObject (readonly)

Returns the value of attribute rails_app.



27
28
29
# File 'lib/kuby/plugins/rails_app/database.rb', line 27

def rails_app
  @rails_app
end

Class Method Details

.get(rails_app) ⇒ Object



14
15
16
17
18
# File 'lib/kuby/plugins/rails_app/database.rb', line 14

def self.get(rails_app)
  if rails_app.manage_database?
    new(rails_app)
  end
end

.get_adapter(adapter_name) ⇒ Object



20
21
22
23
24
25
# File 'lib/kuby/plugins/rails_app/database.rb', line 20

def self.get_adapter(adapter_name)
  ADAPTER_MAP.fetch(adapter_name) do
    raise UnsupportedDatabaseError, "Kuby does not support the '#{adapter_name}' "\
      'database adapter'
  end
end

Instance Method Details

#adapter_nameObject Also known as: plugin_name



39
40
41
# File 'lib/kuby/plugins/rails_app/database.rb', line 39

def adapter_name
  @adapter_name ||= db_config['adapter'].to_sym
end

#pluginObject



33
34
35
36
37
# File 'lib/kuby/plugins/rails_app/database.rb', line 33

def plugin
  @plugin ||= self.class
    .get_adapter(adapter_name)
    .new(rails_app.environment, db_configs)
end