Class: Bretels::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/bretels/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #download_file, #replace_in_file

Instance Method Details

#add_airbrake_configurationObject



207
208
209
# File 'lib/bretels/app_builder.rb', line 207

def add_airbrake_configuration
  copy_file 'airbrake.rb', 'config/initializers/airbrake.rb'
end

#add_cdn_settingsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bretels/app_builder.rb', line 36

def add_cdn_settings
  config = <<-RUBY
\n\n  # Cloudfront settings
  config.static_cache_control = "public, max-age=31536000"
  config.action_controller.asset_host = ENV['ASSET_HOST']

  # Enable Rack Zippy for GZIP responses
  config.middleware.swap(ActionDispatch::Static, Rack::Zippy::AssetServer)
  RUBY

  inject_into_file 'config/environments/production.rb', config.rstrip,
    :after => "config.assets.digest = true"
end

#add_support_filesObject



18
19
20
21
22
# File 'lib/bretels/app_builder.rb', line 18

def add_support_files
  copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb'
  copy_file 'database_cleaner.rb', 'spec/support/database_cleaner.rb'
  copy_file 'poltergeist.rb', 'spec/support/poltergeist.rb'
end

#configure_action_mailerObject



154
155
156
157
158
159
# File 'lib/bretels/app_builder.rb', line 154

def configure_action_mailer
  action_mailer_host 'development', "#{app_name}.dev"
  action_mailer_host 'test', 'www.example.com'
  action_mailer_host 'staging', "#{app_name}-staging.herokuapp.com"
  action_mailer_host 'production', "#{app_name}.nl"
end

#configure_dutch_languageObject



140
141
142
143
144
# File 'lib/bretels/app_builder.rb', line 140

def configure_dutch_language
  replace_in_file 'config/application.rb',
    '# config.i18n.default_locale = :de',
    "config.i18n.default_locale = :nl\n    config.i18n.available_locales = :nl"
end

#configure_rack_timeoutObject



150
151
152
# File 'lib/bretels/app_builder.rb', line 150

def configure_rack_timeout
  copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
end

#configure_rspecObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bretels/app_builder.rb', line 116

def configure_rspec
  config = <<-RUBY

# Hand-pick the generators we use
config.generators do |generate|
  generate.test_framework :rspec
  generate.helper false
  generate.stylesheets false
  generate.javascript_engine false
  generate.request_specs false
  generate.routing_specs false
  generate.view_specs false
end
  RUBY

  inject_into_class 'config/application.rb', 'Application', config
end

#configure_time_formatsObject



146
147
148
# File 'lib/bretels/app_builder.rb', line 146

def configure_time_formats
  copy_file 'config_locales_nl.yml', 'config/locales/nl.yml'
end

#configure_time_zoneObject



134
135
136
137
138
# File 'lib/bretels/app_builder.rb', line 134

def configure_time_zone
  replace_in_file 'config/application.rb',
    "# config.time_zone = 'Central Time (US & Canada)'",
    "config.time_zone = 'Amsterdam'"
end

#create_application_layoutObject



95
96
97
98
99
# File 'lib/bretels/app_builder.rb', line 95

def create_application_layout
  template 'suspenders_layout.html.erb.erb',
    'app/views/layouts/application.html.erb',
    :force => true
end

#create_heroku_appsObject



195
196
197
198
199
# File 'lib/bretels/app_builder.rb', line 195

def create_heroku_apps
  run "#{path_addition} heroku create #{app_name}-production --remote=production"
  run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
  run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
end

#create_partials_directoryObject



87
88
89
# File 'lib/bretels/app_builder.rb', line 87

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



91
92
93
# File 'lib/bretels/app_builder.rb', line 91

def create_shared_flashes
  copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
end

#enable_force_sslObject



67
68
69
70
# File 'lib/bretels/app_builder.rb', line 67

def enable_force_ssl
  replace_in_file 'config/environments/production.rb',
    '# config.force_ssl = true', 'config.force_ssl = true'
end

#enable_rack_deflaterObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/bretels/app_builder.rb', line 50

def enable_rack_deflater
  config = <<-RUBY

  # Enable deflate / gzip compression of controller-generated responses
  config.middleware.use Rack::Deflater
  RUBY

  inject_into_file 'config/environments/production.rb', config,
    :after => "config.serve_static_assets = false\n"
end

#generate_factories_fileObject



28
29
30
# File 'lib/bretels/app_builder.rb', line 28

def generate_factories_file
  empty_directory 'spec/factories'
end

#generate_rspecObject



161
162
163
164
# File 'lib/bretels/app_builder.rb', line 161

def generate_rspec
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
  copy_file 'rails_helper.rb', 'spec/rails_helper.rb'
end

#gitignore_filesObject



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/bretels/app_builder.rb', line 177

def gitignore_files
  concat_file 'suspenders_gitignore', '.gitignore'
  [
    'spec/features',
    'spec/models',
    'spec/support'
  ].each do |dir|
    empty_directory(dir)
    create_file("#{dir}/.gitkeep")
  end
end

#init_gitObject



189
190
191
192
193
# File 'lib/bretels/app_builder.rb', line 189

def init_git
  run 'git init'
  run 'git add .'
  run 'git commit -m "Initial commit" > /dev/null'
end

#initialize_on_precompileObject



76
77
78
79
80
# File 'lib/bretels/app_builder.rb', line 76

def initialize_on_precompile
  inject_into_file 'config/application.rb',
    "\n    config.assets.initialize_on_precompile = false",
    :after => 'config.assets.enabled = true'
end

#install_spring_gemObject



32
33
34
# File 'lib/bretels/app_builder.rb', line 32

def install_spring_gem
  `gem install spring spring-commands-rspec`
end

#lib_in_load_pathObject



82
83
84
85
# File 'lib/bretels/app_builder.rb', line 82

def lib_in_load_path
  inject_into_file 'config/application.rb', "\n\n" + '    config.autoload_paths += Dir["#{config.root}/lib/**/"]',
    after: /class Application < Rails::Application/
end

#raise_delivery_errorsObject



13
14
15
16
# File 'lib/bretels/app_builder.rb', line 13

def raise_delivery_errors
  replace_in_file 'config/environments/development.rb',
    'raise_delivery_errors = false', 'raise_delivery_errors = true'
end

#raise_unpermitted_paramsObject



211
212
213
214
215
216
217
218
# File 'lib/bretels/app_builder.rb', line 211

def raise_unpermitted_params
  config = <<-RUBY
\n\n  config.action_controller.action_on_unpermitted_parameters = :raise
  RUBY

  inject_into_file 'config/environments/development.rb', config.rstrip,
    :after => "config.assets.debug = true"
end

#readmeObject



5
6
7
# File 'lib/bretels/app_builder.rb', line 5

def readme
  template 'README.md.erb', 'README.md'
end

#remove_rails_logo_imageObject



9
10
11
# File 'lib/bretels/app_builder.rb', line 9

def remove_rails_logo_image
  remove_file 'app/assets/images/rails.png'
end

#remove_routes_comment_linesObject



201
202
203
204
205
# File 'lib/bretels/app_builder.rb', line 201

def remove_routes_comment_lines
  replace_in_file 'config/routes.rb',
    /Rails\.application\.routes\.draw do.*end/m,
    "Rails.application.routes.draw do\nend"
end


61
62
63
64
65
# File 'lib/bretels/app_builder.rb', line 61

def remove_turbolinks
  replace_in_file 'app/assets/javascripts/application.js',
    /\/\/= require turbolinks\n/,
    ''
end

#replace_gemfileObject



106
107
108
109
# File 'lib/bretels/app_builder.rb', line 106

def replace_gemfile
  remove_file 'Gemfile'
  copy_file 'Gemfile_clean', 'Gemfile'
end

#set_ruby_to_version_being_usedObject



111
112
113
114
# File 'lib/bretels/app_builder.rb', line 111

def set_ruby_to_version_being_used
  inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
    after: /source 'https:\/\/rubygems.org'/
end

#setup_foremanObject



166
167
168
169
# File 'lib/bretels/app_builder.rb', line 166

def setup_foreman
  copy_file 'puma.rb', 'config/puma.rb'
  copy_file 'Procfile', 'Procfile'
end

#setup_staging_environmentObject



72
73
74
# File 'lib/bretels/app_builder.rb', line 72

def setup_staging_environment
  template 'staging.rb.erb', 'config/environments/staging.rb'
end

#setup_stylesheetsObject



171
172
173
174
175
# File 'lib/bretels/app_builder.rb', line 171

def setup_stylesheets
  copy_file 'app/assets/stylesheets/application.css',
    'app/assets/stylesheets/application.css.scss'
  remove_file 'app/assets/stylesheets/application.css'
end

#test_factories_firstObject



24
25
26
# File 'lib/bretels/app_builder.rb', line 24

def test_factories_first
  copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb'
end

#use_postgres_config_templateObject



101
102
103
104
# File 'lib/bretels/app_builder.rb', line 101

def use_postgres_config_template
  template 'postgresql_database.yml.erb', 'config/database.yml',
    :force => true
end