Class: Starter::Orms

Inherits:
Object
  • Object
show all
Defined in:
lib/starter/builder/orms.rb

Class Method Summary collapse

Class Method Details

.build(dest, orm) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/starter/builder/orms.rb', line 6

def build(dest, orm)
  @orm = orm
  case orm.downcase
  when 'sequel'
    require 'starter/builder/templates/sequel'
    extend(::Starter::Templates::Sequel)
  when 'activerecord', 'ar'
    require 'starter/builder/templates/activerecord'
    extend(::Starter::Templates::ActiveRecord)
    # Fixes pooling
    add_middleware(dest, 'ActiveRecord::Rack::ConnectionManagement')
  else
    return
  end

  build_initializer(File.join(dest, 'config', 'initializers'))
  build_config(File.join(dest, 'config'))
  append_to_file(File.join(dest, 'Rakefile'), rakefile)
  append_to_file(File.join(dest, 'Gemfile'), gemfile)
  prepare_for_migrations(File.join(dest, 'db'))

  Starter::Config.save(dest: dest, content: { orm: orm.downcase })
end

.configObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/starter/builder/orms.rb', line 30

def config
  <<-FILE.strip_heredoc
  # ActiveRecord Database Configuration
  development:
    adapter: '#{adapter}'
    host: localhost
    port: 27017
    database: "db/development.sqlite3"
    username:
    password:

  test:
    adapter: '#{adapter}'
    host: localhost
    port: 27017
    database: "db/test.sqlite3"
    username:
    password:

  production:
    adapter: '#{adapter}'
    host: localhost
    port: 27017
    database: "db/production.sqlite3"
    username:
    password:
  FILE
end