Class: Hanami::Generators::DatabaseConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/generators/database_config.rb

Constant Summary collapse

SUPPORTED_ENGINES =
{
  'mysql'      => { type: :sql,         mri: 'mysql2',  jruby: 'jdbc-mysql'    },
  'mysql2'     => { type: :sql,         mri: 'mysql2',  jruby: 'jdbc-mysql'    },
  'postgresql' => { type: :sql,         mri: 'pg',      jruby: 'jdbc-postgres' },
  'postgres'   => { type: :sql,         mri: 'pg',      jruby: 'jdbc-postgres' },
  'sqlite'     => { type: :sql,         mri: 'sqlite3', jruby: 'jdbc-sqlite3'  },
  'sqlite3'    => { type: :sql,         mri: 'sqlite3', jruby: 'jdbc-sqlite3'  }
}.freeze
DEFAULT_ENGINE =
'sqlite'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, name) ⇒ DatabaseConfig

Returns a new instance of DatabaseConfig


20
21
22
23
24
25
26
27
28
# File 'lib/hanami/generators/database_config.rb', line 20

def initialize(engine, name)
  @engine = engine
  @name = name

  unless SUPPORTED_ENGINES.key?(engine.to_s) # rubocop:disable Style/GuardClause
    warn %(`#{engine}' is not a valid database engine)
    exit(1)
  end
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine


18
19
20
# File 'lib/hanami/generators/database_config.rb', line 18

def engine
  @engine
end

#nameObject (readonly)

Returns the value of attribute name


18
19
20
# File 'lib/hanami/generators/database_config.rb', line 18

def name
  @name
end

Instance Method Details

#sql?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/hanami/generators/database_config.rb', line 42

def sql?
  type == :sql
end

#sqlite?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/hanami/generators/database_config.rb', line 46

def sqlite?
  ['sqlite', 'sqlite3'].include?(engine)
end

#to_hashObject


30
31
32
33
34
35
36
# File 'lib/hanami/generators/database_config.rb', line 30

def to_hash
  {
    gem: gem,
    uri: uri,
    type: type
  }
end

#typeObject


38
39
40
# File 'lib/hanami/generators/database_config.rb', line 38

def type
  SUPPORTED_ENGINES[engine][:type]
end