Class: Hanami::CLI::Commands::New::DatabaseConfig Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli/commands/new.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0

Constant Summary collapse

SUPPORTED_ENGINES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0

{
  '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 =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0

'sqlite'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, name) ⇒ DatabaseConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DatabaseConfig

Since:

  • 1.1.0


40
41
42
43
44
45
46
47
48
# File 'lib/hanami/cli/commands/new.rb', line 40

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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


32
33
34
# File 'lib/hanami/cli/commands/new.rb', line 32

def engine
  @engine
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


36
37
38
# File 'lib/hanami/cli/commands/new.rb', line 36

def name
  @name
end

Instance Method Details

#sql?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 1.1.0


68
69
70
# File 'lib/hanami/cli/commands/new.rb', line 68

def sql?
  type == :sql
end

#sqlite?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 1.1.0


74
75
76
# File 'lib/hanami/cli/commands/new.rb', line 74

def sqlite?
  %w[sqlite sqlite3].include?(engine)
end

#to_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


52
53
54
55
56
57
58
# File 'lib/hanami/cli/commands/new.rb', line 52

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

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


62
63
64
# File 'lib/hanami/cli/commands/new.rb', line 62

def type
  SUPPORTED_ENGINES[engine][:type]
end