Class: Kowl::Overrides::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Defined in:
lib/kowl/generators/overrides/app_builder.rb

Instance Method Summary collapse

Instance Method Details

#database_ymlObject

Override the default generated database.yml file



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/kowl/generators/overrides/app_builder.rb', line 43

def database_yml
  # Application will be defaulted to using sqlite3, until ready
  # => Application will also have a database[database].yml file to replace and run once the application is read
  template 'config/db/sqlite3.yml', 'config/database.yml', force: true

  # The directory config/databases/** is already used by Rails. We don't want to override this, because it won't pull from the gems template files, because they already exist in the rails gem
  # /Users/username/.rvm/gems/ruby-2.6.2/gems/railties-6.0.0/lib/rails/generators/rails/app/templates/config/databases
  if %w[mysql oracle postgresql sqlite3 sqlserver].include? options[:database]
    template "config/db/#{options[:database]}.yml", "config/database[#{options[:database]}].yml" unless options[:database] == 'sqlite3'
  else
    template "config/databases/#{options[:database]}.yml", "config/database[#{options[:database]}].yml"
  end
end

#gitignoreObject

Override the applications .gitignore file with a more rails specific one



10
11
12
# File 'lib/kowl/generators/overrides/app_builder.rb', line 10

def gitignore
  copy_file 'dotfiles/gitignore', '.gitignore', force: true
end

#procfileObject

Generate procfile for anyone who uses foreman to run their rails application, sidekiq, and various other services at once



23
24
25
26
27
28
# File 'lib/kowl/generators/overrides/app_builder.rb', line 23

def procfile
  # Generate base Procfile
  template 'dotfiles/Procfile.tt', 'Procfile'
  # Generate Procfile running foreman in development
  template 'dotfiles/Procfile.tt', 'Procfile.dev', env: 'development'
end

#readmeObject

Override the rails applications README with a new one (displaying application specific information in the readme)



15
16
17
18
19
20
# File 'lib/kowl/generators/overrides/app_builder.rb', line 15

def readme
  template 'README.md.erb', 'README.md'
  # This is here, because if --skip_tests is added, it skips running the gitignore function
  # => since all projects have a readme this should just overwrite the gitignore file
  copy_file 'dotfiles/gitignore', '.gitignore', force: true
end

#replace_gemfileObject

Replace the applications Gemfile with gems that are made to get you started faster



36
37
38
39
40
# File 'lib/kowl/generators/overrides/app_builder.rb', line 36

def replace_gemfile
  # Gemfile template needs to be 'Gemfile.erb' otherwise it attempts to fetch Gemfile template from the Rails gem
  # https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/Gemfile.tt#L9
  template 'Gemfile.erb', 'Gemfile', force: true
end

#setup_springObject

Regenerate the applications spring based binstubs



31
32
33
# File 'lib/kowl/generators/overrides/app_builder.rb', line 31

def setup_spring
  bundle_command 'exec spring binstub --all'
end