Class: Lotus::Generators::DatabaseConfig

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

Overview

Since:

  • 0.1.0

Constant Summary collapse

SUPPORTED_ENGINES =

Since:

  • 0.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'  },
  'filesystem' => { type: :file_system, mri: nil,       jruby: nil             },
  'memory'     => { type: :memory,      mri: nil,       jruby: nil             }
}.freeze
DEFAULT_ENGINE =

Since:

  • 0.1.0

'filesystem'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, name) ⇒ DatabaseConfig

Returns a new instance of DatabaseConfig.

Since:

  • 0.1.0



22
23
24
25
26
27
# File 'lib/lotus/generators/database_config.rb', line 22

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

  SUPPORTED_ENGINES.key?(engine.to_s) or fail "\"#{ engine }\" is not a valid database type"
end

Instance Attribute Details

#engineObject (readonly)

Since:

  • 0.1.0



20
21
22
# File 'lib/lotus/generators/database_config.rb', line 20

def engine
  @engine
end

#nameObject (readonly)

Since:

  • 0.1.0



20
21
22
# File 'lib/lotus/generators/database_config.rb', line 20

def name
  @name
end

Instance Method Details

#filesystem?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



45
46
47
# File 'lib/lotus/generators/database_config.rb', line 45

def filesystem?
  type == :file_system
end

#sql?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



41
42
43
# File 'lib/lotus/generators/database_config.rb', line 41

def sql?
  type == :sql
end

#to_hashObject

Since:

  • 0.1.0



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

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

#typeObject

Since:

  • 0.1.0



37
38
39
# File 'lib/lotus/generators/database_config.rb', line 37

def type
  SUPPORTED_ENGINES[engine][:type]
end